﻿/* Copyright (c) 2007 Google Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Google.Apps.Reporting
{
    public abstract class ReportRecord : IComparable<ReportRecord>
    {
        #region internal variables

        internal DateTime _Date;

        #endregion

        #region properties

        /// <summary>
        /// The date field specifies the day, month and year that correspond to the remaining data in a row of a report.
        /// </summary>
        public DateTime Date { get { return _Date; } set { _Date = value; } }

        #endregion

        #region comparers

        /// <summary>
        /// date based compare - date present on all report record types.
        /// NOTE FIRST ITEM WILL BE LOWEST TIME (e.g. 1970 is less than 1980)
        /// if want this back to front reverse order of the collection being sorted
        /// </summary>
        /// <param name="other">object for comparison</param>
        /// <returns>compare int</returns>
        int IComparable<ReportRecord>.CompareTo(ReportRecord other)
        {
            if (other == null) return 1;
            if (other == this) return 0;

            return DateTime.Compare(this.Date, other.Date);
        }

        public static IComparer<ReportRecord> ReportDateSorter { get { return new ReportDateComparer(); } }

        /// <summary>
        /// compare records based on date
        /// is datetime compare on date property of report record
        /// </summary>
        private class ReportDateComparer : IComparer<ReportRecord>
        {
            int IComparer<ReportRecord>.Compare(ReportRecord x, ReportRecord y)
            {
                if (x == null && y == null) return 0;
                else if (x == null) return -1;
                else if (y == null) return 1;
                if (x == y) return 0;

                if (x.Date == null && y.Date == null) return 0;
                else if (x.Date == null) return -1;
                else if (y.Date == null) return 1;
                if (x.Date == y.Date) return 0;

                return x.Date.CompareTo(y.Date);
            }
        }

        #endregion
    }

    /// <summary>
    /// A google apps reporting Accounts Report Record
    /// </summary>
    public class AccountsReportRecord : Google.Apps.Reporting.ReportRecord
    {
        #region overrides

        /// <summary>
        /// returns string of report record in format that like that originally delivered in report query
        /// NOTE space chars between CSVs specified in v1.0.1 API documentation
        /// </summary>
        /// <returns>report record in format that like that originally delivered in report query</returns>
        public override string ToString()
        {
            /**date, account_id, account_name, status, quota_in_mb, usage_in_bytes, primary_account_id, 
             * primary_account_name, creation_date, last_login_date, last_web_mail_date, surname, given_name,
             * service_tier, channel, suspension_reason, last_pop_date, creation_time, last_login_time, last_web_mail_time, last_pop_time **/
            return this.Date.ToString("yyyyMMdd") + "," + this.Account_id + "," + this.Account_name + "," + this.Account_status.ToString() + "," + this.Quota_in_mb
                  + "," + this.Usage_in_bytes + "," + this.Primary_account_id + "," + this.Primary_account_name + this.Creation_date.ToString("yyyyMMdd")
                  + "," + this.Last_login_date.ToString("yyyyMMdd") + "," + this.Last_web_mail_date.ToString("yyyyMMdd") + "," + this.Surname
                  + "," + this.Given_name + "," + this.Service_tier + "," + this.Channel + "," + this.Suspension_reason + "," + this.Last_pop_date.ToString("yyyyMMdd")
                  + "," + this.Creation_time.ToString("yyyy-MM-dd HH:mm:ss") + "," + this.Last_login_time.ToString("yyyy-MM-dd HH:mm:ss") + "," +
                  this.Last_web_mail_time.ToString("yyyy-MM-dd HH:mm:ss") + "," + this.Last_pop_time.ToString("yyyy-MM-dd HH:mm:ss");
        }
        #endregion

        #region instantiation

        /// <summary>
        /// default instantiation
        /// </summary>
        public AccountsReportRecord() { }

        /// <summary>
        /// parses string from google report.  
        /// API v1.0.1 this will be a comma delimited string
        /// </summary>
        /// <param name="googleReturnedReportRecordString">string of date,account_id,account_name,status,quota_in_mb,usage_in_bytes,primary_account_id,
        /// primary_account_name, creation_date,last_login_date,last_web_mail_date,surname,given_name,service_tier,channel,suspension_reason, 
        /// last_pop_date,creation_time,last_login_time,last_web_mail_time,last_pop_time</param>
        public AccountsReportRecord(string googleReturnedReportRecordString)
        {
            int expectedSplitLength = 21; // API v1.0.1 account report record
            string[] split = null;
            int currentPos = 0;

            try
            {
                split = googleReturnedReportRecordString.Split(',');
            }
            catch (Exception)
            {
                throw new FormatException("cannot split passed string in report record instantiation from google reporting returned string");
            }

            if (split.Length != expectedSplitLength)
            {
                throw new FormatException("passed string split to array of non-expected size - seen: " + split.Length + " expected: " + expectedSplitLength);
            }

            //     0123 45 67
            //e.g. 2011 01 18 - will not parse properly if fed to datetime.parse 
            try { this._Date = new DateTime(Convert.ToInt32(split[0].Substring(0, 4)), Convert.ToInt32(split[0].Substring(4, 2)), Convert.ToInt32(split[0].Substring(6, 2))); }
            catch (Exception) { throw new FormatException("could not parse DateTime from data: " + split[0]); }

            this._Account_id = split[1];
            this._Account_name = split[2];

            if (split[3] == "ACTIVE") this._Account_status = Status.ACTIVE;
            else if (split[3] == "SUSPENDED") this._Account_status = Status.SUSPENDED;
            else if (split[3] == "SUSPENDED_BY_ADMIN") this._Account_status = Status.SUSPENDED_BY_ADMIN;
            else if (split[3] == "SUSPENDED_FOR_ABUSE") this._Account_status = Status.SUSPENDED_FOR_ABUSE;
            else throw new FormatException("could not parse account report record status to valid value from data: " + split[3]);

            currentPos = 4;
            try
            {
                this._Quota_in_mb = Convert.ToInt32(split[4]); currentPos++;
                this._Usage_in_bytes = Convert.ToInt32(split[5]);
            }
            catch (Exception) { throw new FormatException("could not parse from data: " + split[currentPos]); }

            this._Primary_account_id = split[6];
            this._Primary_account_name = split[7];

            currentPos = 8;
            try
            {
                this._Creation_date = new DateTime(Convert.ToInt32(split[8].Substring(0, 4)), Convert.ToInt32(split[8].Substring(4, 2)), Convert.ToInt32(split[8].Substring(6, 2))); currentPos++;
                this._Last_login_date = new DateTime(Convert.ToInt32(split[9].Substring(0, 4)), Convert.ToInt32(split[9].Substring(4, 2)), Convert.ToInt32(split[9].Substring(6, 2))); currentPos++;
                this._Last_web_mail_date = new DateTime(Convert.ToInt32(split[10].Substring(0, 4)), Convert.ToInt32(split[10].Substring(4, 2)), Convert.ToInt32(split[10].Substring(6, 2)));
            }
            catch (Exception) { throw new FormatException("could not parse from data: " + split[currentPos]); }

            this._Surname = split[11];
            this._Given_name = split[12];
            this._Service_tier = split[13];
            this._Channel = split[14];
            this._Suspension_reason = split[15];

            currentPos = 16;
            try
            {
                this._Last_pop_date = new DateTime(Convert.ToInt32(split[16].Substring(0, 4)), Convert.ToInt32(split[16].Substring(4, 2)), Convert.ToInt32(split[16].Substring(6, 2))); currentPos++;
                this._Creation_time = DateTime.Parse(split[17]); currentPos++;
                this._Last_login_time = DateTime.Parse(split[18]); currentPos++;
                this._Last_web_mail_time = DateTime.Parse(split[19]); currentPos++;
                this._Last_pop_time = DateTime.Parse(split[20]);
            }
            catch (Exception) { throw new FormatException("could not parse from data: " + split[currentPos]); }
        }

        #endregion

        #region comparers

        public static IComparer<AccountsReportRecord> AccountIdSorter { get { return new AccountIdComparer(); } }
        public static IComparer<AccountsReportRecord> AccountNameSorter { get { return new AccountNameComparer(); } }
        public static IComparer<AccountsReportRecord> AccountStatusSorter { get { return new AccountStatusComparer(); } }
        public static IComparer<AccountsReportRecord> AccountQuotaInMBSorter { get { return new AccountQuotaInMbComparer(); } }
        public static IComparer<AccountsReportRecord> AccountUsageInBytesSorter { get { return new AccountUsageInBytesComparer(); } }
        public static IComparer<AccountsReportRecord> AccountPrimaryIdSorter { get { return new AccountPrimaryIdComparer(); } }
        public static IComparer<AccountsReportRecord> AccountPrimaryNameSorter { get { return new AccountPrimaryNameComparer(); } }
        public static IComparer<AccountsReportRecord> AccountCreationDateSorter { get { return new AccountCreationDateComparer(); } }
        public static IComparer<AccountsReportRecord> AccountLastLoginDateSorter { get { return new AccountLastLoginDateComparer(); } }
        public static IComparer<AccountsReportRecord> AccountLastWebMailDateSorter { get { return new AccountLastWebMailDateComparer(); } }
        public static IComparer<AccountsReportRecord> AccountCreationTimeSorter { get { return new AccountCreationTimeComparer(); } }
        public static IComparer<AccountsReportRecord> AccountLastLoginTimeSorter { get { return new AccountLastLoginTimeComparer(); } }
        public static IComparer<AccountsReportRecord> AccountLastWebMailTimeSorter { get { return new AccountLastWebMailTimeComparer(); } }
        public static IComparer<AccountsReportRecord> AccountSurnameSorter { get { return new AccountSurnameComparer(); } }
        public static IComparer<AccountsReportRecord> AccountGivenNameSorter { get { return new AccountGivenNameComparer(); } }
        public static IComparer<AccountsReportRecord> AccountServiceTierSorter { get { return new AccountServiceTierComparer(); } }
        public static IComparer<AccountsReportRecord> AccountChannelSorter { get { return new AccountChannelComparer(); } }
        public static IComparer<AccountsReportRecord> AccountSuspensionReasonSorter { get { return new AccountSuspensionReasonComparer(); } }
        public static IComparer<AccountsReportRecord> AccountLastPopDateSorter { get { return new AccountLastPopDateComparer(); } }
        public static IComparer<AccountsReportRecord> AccountLastPopTimeSorter { get { return new AccountLastPopTimeComparer(); } }

        /// <summary>
        /// compare records based on account_id
        /// is string compare on Account_id property of Accounts report record
        /// </summary>
        private class AccountIdComparer : IComparer<AccountsReportRecord>
        {
            int IComparer<AccountsReportRecord>.Compare(AccountsReportRecord x, AccountsReportRecord y)
            {
                if (x == null && y == null) return 0;
                else if (x == null) return -1;
                else if (y == null) return 1;
                if (x == y) return 0;

                if (x.Account_id == null && y.Account_id == null) return 0;
                else if (x.Account_id == null) return -1;
                else if (y.Account_id == null) return 1;
                if (x.Account_id == y.Account_id) return 0;

                return x.Account_id.CompareTo(y.Account_id);
            }
        }

        /// <summary>
        /// compare records based on account_name
        /// is string compare on Account_name property of Accounts report record
        /// </summary>
        private class AccountNameComparer : IComparer<AccountsReportRecord>
        {
            int IComparer<AccountsReportRecord>.Compare(AccountsReportRecord x, AccountsReportRecord y)
            {
                if (x == null && y == null) return 0;
                else if (x == null) return -1;
                else if (y == null) return 1;
                if (x == y) return 0;

                if (x.Account_name == null && y.Account_name == null) return 0;
                else if (x.Account_name == null) return -1;
                else if (y.Account_name == null) return 1;
                if (x.Account_name == y.Account_name) return 0;

                return x.Account_name.CompareTo(y.Account_name);
            }
        }

        /// <summary>
        /// compare records based on account_status
        /// is compare on enum int value for Account_status property of Accounts report record
        /// </summary>
        private class AccountStatusComparer : IComparer<AccountsReportRecord>
        {
            int IComparer<AccountsReportRecord>.Compare(AccountsReportRecord x, AccountsReportRecord y)
            {
                if (x == null && y == null) return 0;
                else if (x == null) return -1;
                else if (y == null) return 1;
                if (x == y) return 0;

                return x.Account_status.CompareTo(y.Account_status);
            }
        }

        /// <summary>
        /// compare records based on quota_in_mb
        /// is compate on int value for Account quota_in_mb property of Accounts report record
        /// </summary>
        private class AccountQuotaInMbComparer : IComparer<AccountsReportRecord>
        {
            int IComparer<AccountsReportRecord>.Compare(AccountsReportRecord x, AccountsReportRecord y)
            {
                if (x == null && y == null) return 0;
                else if (x == null) return -1;
                else if (y == null) return 1;
                if (x == y) return 0;

                return x.Quota_in_mb.CompareTo(y.Quota_in_mb);
            }
        }

        /// <summary>
        /// compare records based on usage_in_bytes
        /// is compate on int value for Account usage_in_bytes property of Accounts report record
        /// </summary>
        private class AccountUsageInBytesComparer : IComparer<AccountsReportRecord>
        {
            int IComparer<AccountsReportRecord>.Compare(AccountsReportRecord x, AccountsReportRecord y)
            {
                if (x == null && y == null) return 0;
                else if (x == null) return -1;
                else if (y == null) return 1;
                if (x == y) return 0;

                return x.Usage_in_bytes.CompareTo(y.Usage_in_bytes);
            }
        }

        /// <summary>
        /// compare records based on primary_account_id
        /// is string compare on Primary_account_id property of Accounts report record
        /// </summary>
        private class AccountPrimaryIdComparer : IComparer<AccountsReportRecord>
        {
            int IComparer<AccountsReportRecord>.Compare(AccountsReportRecord x, AccountsReportRecord y)
            {
                if (x == null && y == null) return 0;
                else if (x == null) return -1;
                else if (y == null) return 1;
                if (x == y) return 0;

                if (x.Primary_account_id == null && y.Primary_account_id == null) return 0;
                else if (x.Primary_account_id == null) return -1;
                else if (y.Primary_account_id == null) return 1;
                if (x.Primary_account_id == y.Primary_account_id) return 0;

                return x.Primary_account_id.CompareTo(y.Primary_account_id);
            }
        }

        /// <summary>
        /// compare records based on primary_account_name
        /// is string compare on Primary_account_id property of Accounts report record
        /// </summary>
        private class AccountPrimaryNameComparer : IComparer<AccountsReportRecord>
        {
            int IComparer<AccountsReportRecord>.Compare(AccountsReportRecord x, AccountsReportRecord y)
            {
                if (x == null && y == null) return 0;
                else if (x == null) return -1;
                else if (y == null) return 1;
                if (x == y) return 0;

                if (x.Primary_account_name == null && y.Primary_account_name == null) return 0;
                else if (x.Primary_account_name == null) return -1;
                else if (y.Primary_account_name == null) return 1;
                if (x.Primary_account_name == y.Primary_account_name) return 0;

                return x.Primary_account_name.CompareTo(y.Primary_account_name);
            }
        }

        /// <summary>
        /// compare records based on creation_date
        /// is datetime compare on Creation_date property of Accounts report record
        /// </summary>
        private class AccountCreationDateComparer : IComparer<AccountsReportRecord>
        {
            int IComparer<AccountsReportRecord>.Compare(AccountsReportRecord x, AccountsReportRecord y)
            {
                if (x == null && y == null) return 0;
                else if (x == null) return -1;
                else if (y == null) return 1;
                if (x == y) return 0;

                if (x.Creation_date == null && y.Creation_date == null) return 0;
                else if (x.Creation_date == null) return -1;
                else if (y.Creation_date == null) return 1;
                if (x.Creation_date == y.Creation_date) return 0;

                return x.Creation_date.CompareTo(y.Creation_date);
            }
        }

        /// <summary>
        /// compare records based on last_login_date
        /// is datetime compare on Last_login_date property of Accounts report record
        /// </summary>
        private class AccountLastLoginDateComparer : IComparer<AccountsReportRecord>
        {
            int IComparer<AccountsReportRecord>.Compare(AccountsReportRecord x, AccountsReportRecord y)
            {
                if (x == null && y == null) return 0;
                else if (x == null) return -1;
                else if (y == null) return 1;
                if (x == y) return 0;

                if (x.Last_login_date == null && y.Last_login_date == null) return 0;
                else if (x.Last_login_date == null) return -1;
                else if (y.Last_login_date == null) return 1;
                if (x.Last_login_date == y.Last_login_date) return 0;

                return x.Last_login_date.CompareTo(y.Last_login_date);
            }
        }

        /// <summary>
        /// compare records based on last_web_mail_date
        /// is datetime compare on Last_web_mail_date property of Accounts report record
        /// </summary>
        private class AccountLastWebMailDateComparer : IComparer<AccountsReportRecord>
        {
            int IComparer<AccountsReportRecord>.Compare(AccountsReportRecord x, AccountsReportRecord y)
            {
                if (x == null && y == null) return 0;
                else if (x == null) return -1;
                else if (y == null) return 1;
                if (x == y) return 0;

                if (x.Last_web_mail_date == null && y.Last_web_mail_date == null) return 0;
                else if (x.Last_web_mail_date == null) return -1;
                else if (y.Last_web_mail_date == null) return 1;
                if (x.Last_web_mail_date == y.Last_web_mail_date) return 0;

                return x.Last_web_mail_date.CompareTo(y.Last_web_mail_date);
            }
        }

        /// <summary>
        /// compare records based on creation_time
        /// is datetime compare on Creation_time property of Accounts report record
        /// </summary>
        private class AccountCreationTimeComparer : IComparer<AccountsReportRecord>
        {
            int IComparer<AccountsReportRecord>.Compare(AccountsReportRecord x, AccountsReportRecord y)
            {
                if (x == null && y == null) return 0;
                else if (x == null) return -1;
                else if (y == null) return 1;
                if (x == y) return 0;

                if (x.Creation_time == null && y.Creation_time == null) return 0;
                else if (x.Creation_time == null) return -1;
                else if (y.Creation_time == null) return 1;
                if (x.Creation_time == y.Creation_time) return 0;

                return x.Creation_time.CompareTo(y.Creation_time);
            }
        }

        /// <summary>
        /// compare records based on last_login_time
        /// is datetime compare on Last_login_time property of Accounts report record
        /// </summary>
        private class AccountLastLoginTimeComparer : IComparer<AccountsReportRecord>
        {
            int IComparer<AccountsReportRecord>.Compare(AccountsReportRecord x, AccountsReportRecord y)
            {
                if (x == null && y == null) return 0;
                else if (x == null) return -1;
                else if (y == null) return 1;
                if (x == y) return 0;

                if (x.Last_login_time == null && y.Last_login_time == null) return 0;
                else if (x.Last_login_time == null) return -1;
                else if (y.Last_login_time == null) return 1;
                if (x.Last_login_time == y.Last_login_time) return 0;

                return x.Last_login_time.CompareTo(y.Last_login_time);
            }
        }

        /// <summary>
        /// compare records based on last_web_mail_time
        /// is datetime compare on Last_web_mail_time property of Accounts report record
        /// </summary>
        private class AccountLastWebMailTimeComparer : IComparer<AccountsReportRecord>
        {
            int IComparer<AccountsReportRecord>.Compare(AccountsReportRecord x, AccountsReportRecord y)
            {
                if (x == null && y == null) return 0;
                else if (x == null) return -1;
                else if (y == null) return 1;
                if (x == y) return 0;

                if (x.Last_web_mail_time == null && y.Last_web_mail_time == null) return 0;
                else if (x.Last_web_mail_time == null) return -1;
                else if (y.Last_web_mail_time == null) return 1;
                if (x.Last_web_mail_time == y.Last_web_mail_time) return 0;

                return x.Last_web_mail_time.CompareTo(y.Last_web_mail_time);
            }
        }

        /// <summary>
        /// compare records based on surname
        /// is string compare on Surname property of Accounts report record
        /// </summary>
        private class AccountSurnameComparer : IComparer<AccountsReportRecord>
        {
            int IComparer<AccountsReportRecord>.Compare(AccountsReportRecord x, AccountsReportRecord y)
            {
                if (x == null && y == null) return 0;
                else if (x == null) return -1;
                else if (y == null) return 1;
                if (x == y) return 0;

                if (x.Surname == null && y.Surname == null) return 0;
                else if (x.Surname == null) return -1;
                else if (y.Surname == null) return 1;
                if (x.Surname == y.Surname) return 0;

                return x.Surname.CompareTo(y.Surname);
            }
        }

        /// <summary>
        /// compare records based on given_name
        /// is string compare on Given_name property of Accounts report record
        /// </summary>
        private class AccountGivenNameComparer : IComparer<AccountsReportRecord>
        {
            int IComparer<AccountsReportRecord>.Compare(AccountsReportRecord x, AccountsReportRecord y)
            {
                if (x == null && y == null) return 0;
                else if (x == null) return -1;
                else if (y == null) return 1;
                if (x == y) return 0;

                if (x.Given_name == null && y.Given_name == null) return 0;
                else if (x.Given_name == null) return -1;
                else if (y.Given_name == null) return 1;
                if (x.Given_name == y.Given_name) return 0;

                return x.Given_name.CompareTo(y.Given_name);
            }
        }

        /// <summary>
        /// compare records based on service_tier
        /// is string compare on Service_tier property of Accounts report record
        /// </summary>
        private class AccountServiceTierComparer : IComparer<AccountsReportRecord>
        {
            int IComparer<AccountsReportRecord>.Compare(AccountsReportRecord x, AccountsReportRecord y)
            {
                if (x == null && y == null) return 0;
                else if (x == null) return -1;
                else if (y == null) return 1;
                if (x == y) return 0;

                if (x.Service_tier == null && y.Service_tier == null) return 0;
                else if (x.Service_tier == null) return -1;
                else if (y.Service_tier == null) return 1;
                if (x.Service_tier == y.Service_tier) return 0;

                return x.Service_tier.CompareTo(y.Service_tier);
            }
        }

        /// <summary>
        /// compare records based on channel
        /// is string compare on Channel property of Accounts report record
        /// </summary>
        private class AccountChannelComparer : IComparer<AccountsReportRecord>
        {
            int IComparer<AccountsReportRecord>.Compare(AccountsReportRecord x, AccountsReportRecord y)
            {
                if (x == null && y == null) return 0;
                else if (x == null) return -1;
                else if (y == null) return 1;
                if (x == y) return 0;

                if (x.Channel == null && y.Channel == null) return 0;
                else if (x.Channel == null) return -1;
                else if (y.Channel == null) return 1;
                if (x.Channel == y.Channel) return 0;

                return x.Channel.CompareTo(y.Channel);
            }
        }

        /// <summary>
        /// compare records based on suspension_reason
        /// is string compare on Suspension_reason property of Accounts report record
        /// </summary>
        private class AccountSuspensionReasonComparer : IComparer<AccountsReportRecord>
        {
            int IComparer<AccountsReportRecord>.Compare(AccountsReportRecord x, AccountsReportRecord y)
            {
                if (x == null && y == null) return 0;
                else if (x == null) return -1;
                else if (y == null) return 1;
                if (x == y) return 0;

                if (x.Suspension_reason == null && y.Suspension_reason == null) return 0;
                else if (x.Suspension_reason == null) return -1;
                else if (y.Suspension_reason == null) return 1;
                if (x.Suspension_reason == y.Suspension_reason) return 0;

                return x.Suspension_reason.CompareTo(y.Suspension_reason);
            }
        }

        /// <summary>
        /// compare records based on last_pop_date
        /// is string compare on Last_pop_date property of Accounts report record
        /// </summary>
        private class AccountLastPopDateComparer : IComparer<AccountsReportRecord>
        {
            int IComparer<AccountsReportRecord>.Compare(AccountsReportRecord x, AccountsReportRecord y)
            {
                if (x == null && y == null) return 0;
                else if (x == null) return -1;
                else if (y == null) return 1;
                if (x == y) return 0;

                if (x.Last_pop_date == null && y.Last_pop_date == null) return 0;
                else if (x.Last_pop_date == null) return -1;
                else if (y.Last_pop_date == null) return 1;
                if (x.Last_pop_date == y.Last_pop_date) return 0;

                return x.Last_pop_date.CompareTo(y.Last_pop_date);
            }
        }

        /// <summary>
        /// compare records based on last_pop_time
        /// is string compare on Last_pop_time property of Accounts report record
        /// </summary>
        private class AccountLastPopTimeComparer : IComparer<AccountsReportRecord>
        {
            int IComparer<AccountsReportRecord>.Compare(AccountsReportRecord x, AccountsReportRecord y)
            {
                if (x == null && y == null) return 0;
                else if (x == null) return -1;
                else if (y == null) return 1;
                if (x == y) return 0;

                if (x.Last_pop_time == null && y.Last_pop_time == null) return 0;
                else if (x.Last_pop_time == null) return -1;
                else if (y.Last_pop_time == null) return 1;
                if (x.Last_pop_time == y.Last_pop_time) return 0;

                return x.Last_pop_time.CompareTo(y.Last_pop_time);
            }
        }

        #endregion

        #region internal variables
        /// <summary>
        /// user account status - reporting API v1.0.1 currently has values for ACTIVE, SUSPENDED, SUSPENDED_BY_ADMIN, SUSPENDED_FOR_ABUSE
        /// </summary>
        public enum Status { ACTIVE, SUSPENDED, SUSPENDED_BY_ADMIN, SUSPENDED_FOR_ABUSE }

        private string _Account_id;
        private string _Account_name;
        private AccountsReportRecord.Status _Account_status;
        private int _Quota_in_mb;
        private int _Usage_in_bytes;
        private string _Primary_account_id;
        private string _Primary_account_name;
        private DateTime _Creation_date;
        private DateTime _Last_login_date;
        private DateTime _Last_web_mail_date;
        private string _Surname;
        private string _Given_name;
        private string _Service_tier;
        private string _Channel;
        private string _Suspension_reason;
        private DateTime _Last_pop_date;
        private DateTime _Creation_time;
        private DateTime _Last_login_time;
        private DateTime _Last_web_mail_time;
        private DateTime _Last_pop_time;

        #endregion

        #region properties
        /// <summary>
        /// The account_id field contains an ID that uniquely identifies a hosted account. Google will assign an account 
        /// ID to each hosted account that you create, and this ID will not change for the life of the account.
        /// </summary>
        public string Account_id { get { return _Account_id; } set { _Account_id = value; } }

        /// <summary>
        /// The account_name field contains the user's email address, including a username and your domain name – e.g. admin@example.com.
        /// </summary>
        public string Account_name { get { return _Account_name; } set { _Account_name = value; } }

        /// <summary>
        /// Status of user account - reporting API v1.0.1 currently has values for ACTIVE, SUSPENDED, SUSPENDED_BY_ADMIN, SUSPENDED_FOR_ABUSE
        /// </summary>
        public Status Account_status { get { return _Account_status; } set { _Account_status = value; } }

        /// <summary>
        /// The quota_in_mb field indicates the total amount of disk space available for all of the hosted accounts in your domain.
        /// </summary>
        public int Quota_in_mb { get { return _Quota_in_mb; } set { _Quota_in_mb = value; } }

        /// <summary>
        /// The usage_in_bytes field specifies the total amount of disk space, in bytes, used by all accounts, including suspended 
        /// accounts, active accounts in your domain.
        /// </summary>
        public int Usage_in_bytes { get { return _Usage_in_bytes; } set { _Usage_in_bytes = value; } }

        /// <summary>
        /// The primary_account_id field will contain a value if the specified account is a subsidiary account. In that case, this 
        /// field will contain the account ID that identifies the parent account of the subsidiary account. Otherwise, this field 
        /// will be left blank.  ** API v1.0.1 - Currently, all hosted accounts are primary accounts. As such, this field will always be left blank.**
        /// </summary>
        public string Primary_account_id { get { return _Primary_account_id; } set { _Primary_account_id = value; } }

        /// <summary>
        /// he primary_account_name field will contain a value if the specified account is a subsidiary account. In that case, this 
        /// field will contain the account name for the parent account of the subsidiary account. Otherwise, this field will be left blank.
        /// ** API v1.0.1 - Currently, all hosted accounts are primary accounts. As such, this field will always be left blank. **
        /// </summary>
        public string Primary_account_name { get { return _Primary_account_name; } set { _Primary_account_name = value; } }

        /// <summary>
        /// The creation_date field specifies the date that the account was created.  
        /// ** note lower resolution than Creation_time **
        /// </summary>
        public DateTime Creation_date { get { return _Creation_date; } set { _Creation_date = value; } }

        /// <summary>
        /// The Last_login_date field specifies the most recent date that the account owner logged into the specified account. 
        /// ** note lower resolution than Last_login_time **
        /// </summary>
        public DateTime Last_login_date { get { return _Last_login_date; } set { _Last_login_date = value; } }

        /// <summary>
        /// The last_web_mail_date field specifies the most recent date that email for an account was accessed using WebMail.
        /// ** note lower resolution than Last_web_mail_time **
        /// </summary>
        public DateTime Last_web_mail_date { get { return _Last_web_mail_date; } set { _Last_web_mail_date = value; } }

        /// <summary>
        /// The surname field contains the last name of the user who owns the account.
        /// </summary>
        public string Surname { get { return _Surname; } set { _Surname = value; } }

        /// <summary>
        /// The given_name field contains the first name of the user who owns the account.
        /// </summary>
        public string Given_name { get { return _Given_name; } set { _Given_name = value; } }

        /// <summary>
        /// The service_tier field is reserved for future use. 
        /// ** API v1.0.1 - Currently, this field will contain an empty value. **
        /// </summary>
        public string Service_tier { get { return _Service_tier; } set { _Service_tier = value; } }

        /// <summary>
        /// The channel field is reserved for future use.
        /// ** API v1.0.1 - Currently, this field will contain an empty value. **
        /// </summary>
        public string Channel { get { return _Channel; } set { _Channel = value; } }

        /// <summary>
        /// The suspension_reason field identifies the reason that an account was suspended
        /// </summary>
        public string Suspension_reason { get { return _Suspension_reason; } set { _Suspension_reason = value; } }

        /// <summary>
        /// The last_pop_date field specifies the most recent date that email for an account was accessed using POP
        /// ** note lower resolution than 
        /// </summary>
        public DateTime Last_pop_date { get { return _Last_pop_date; } set { _Last_pop_date = value; } }

        /// <summary>
        /// The creation_time field specifies the date and time that the account was created.
        /// ** note higher resolution than Creation_date **
        /// </summary>
        public DateTime Creation_time { get { return _Creation_time; } set { _Creation_time = value; } }

        /// <summary>
        /// The last_login_time field specifies the most recent date and time that the account owner logged into the specified account.
        /// ** note higher resolution than Last_login_date **
        /// </summary>
        public DateTime Last_login_time { get { return _Last_login_time; } set { _Last_login_time = value; } }

        /// <summary>
        /// The last_web_mail_time field specifies the most recent date and time that email for an account was accessed using WebMail.
        /// ** note higher resolution than Last_web_mail_date **
        /// </summary>
        public DateTime Last_web_mail_time { get { return _Last_web_mail_time; } set { _Last_web_mail_time = value; } }

        /// <summary>
        /// The last_pop_time field specifies the most recent date that and time email for an account was accessed using POP.
        /// ** note higher resultion than Last_pop_date **
        /// </summary>
        public DateTime Last_pop_time { get { return _Last_pop_time; } set { _Last_pop_time = value; } }

        #endregion
    }

    /// <summary>
    /// The activity report identifies the total number of accounts in your domain as well as the number of active and idle accounts 
    /// over several different time periods. In this report, activity encompasses user interaction with his email, such as reading or 
    /// sending email. The activity statistics includes web mail as well as POP activity.
    /// </summary>
    public class ActivityReportRecord : Google.Apps.Reporting.ReportRecord
    {
        #region overrides
        /// <summary>
        /// returns string of report record in format that like that originally delivered in report query
        /// </summary>
        /// <returns>report record in format that like that originally delivered in report query</returns>
        public override string ToString()
        {
            /**
             * date,num_accounts,count_1_day_actives,count_7_day_actives,count_14_day_actives, count_30_day_actives,count_30_day_idle,count_60_day_idle,count_90_day_idle
             **/
            return this.Date.ToString("yyyyMMdd") + "," + this.Num_accounts + "," + this.Count_1_day_actives + "," + this.Count_7_day_actives + ","
                + this.Count_14_day_actives + "," + this.Count_30_day_actives + "," + this.Count_30_day_idle + "," + this.Count_60_day_idle + ","
                + this.Count_90_day_idle;
        }
        #endregion

        #region instantiation

        /// <summary>
        /// default instantiation
        /// </summary>
        public ActivityReportRecord() { }

        /// <summary>
        /// parses string from google report.  
        /// API v1.0.1 this will be a comma delimited string
        /// </summary>
        /// <param name="googleReturnedReportRecordString">date,num_accounts,count_1_day_actives,count_7_day_actives,count_14_day_actives, 
        /// count_30_day_actives,count_30_day_idle,count_60_day_idle,count_90_day_idle</param>
        public ActivityReportRecord(string googleReturnedReportRecordString)
        {
            int expectedSplitLength = 9; // API v1.0.1 activity report record
            string[] split = null;
            int currentpos = 0;
            try
            {
                split = googleReturnedReportRecordString.Split(',');
            }
            catch (Exception)
            {
                throw new FormatException("cannot split passed string in report record instantiation from google reporting returned string");
            }

            if (split.Length != expectedSplitLength)
            {
                throw new FormatException("passed string split to array of non-expected size - seen: " + split.Length + " expected: " + expectedSplitLength);
            }


            try
            {
                this._Date = new DateTime(Convert.ToInt32(split[0].Substring(0, 4)), Convert.ToInt32(split[0].Substring(4, 2)), Convert.ToInt32(split[0].Substring(6, 2))); currentpos++;
                this._Num_accounts = Convert.ToInt32(split[1]); currentpos++;
                this._Count_1_day_actives = Convert.ToInt32(split[2]); currentpos++;
                this._Count_7_day_actives = Convert.ToInt32(split[3]); currentpos++;
                this._Count_14_day_actives = Convert.ToInt32(split[4]); currentpos++;
                this.Count_30_day_actives = Convert.ToInt32(split[5]); currentpos++;
                this._Count_30_day_idle = Convert.ToInt32(split[6]); currentpos++;
                this._Count_60_day_idle = Convert.ToInt32(split[7]); currentpos++;
                this._Count_90_day_idle = Convert.ToInt32(split[8]);
            }
            catch (Exception) { throw new FormatException("could not parse from data: " + split[currentpos]); }

        }

        #endregion

        #region comparers

        public static IComparer<ActivityReportRecord> ActivityNumAccountsSorter { get { return new ActivityNumAccountsComparer(); } }
        public static IComparer<ActivityReportRecord> Activity1DayActivesSorter { get { return new Activity1DayActivesComparer(); } }
        public static IComparer<ActivityReportRecord> Activity7DayActivesSorter { get { return new Activity7DayActivesComparer(); } }
        public static IComparer<ActivityReportRecord> Activity14DayActivesSorter { get { return new Activity14DayActivesComparer(); } }
        public static IComparer<ActivityReportRecord> Activity30DayActivesSorter { get { return new Activity30DayActivesComparer(); } }
        public static IComparer<ActivityReportRecord> Activity30DayIdleSorter { get { return new Activity30DayIdleComparer(); } }
        public static IComparer<ActivityReportRecord> Activity60DayIdleSorter { get { return new Activity60DayIdleComparer(); } }
        public static IComparer<ActivityReportRecord> Activity90DayIdleSorter { get { return new Activity90DayIdleComparer(); } }

        /// <summary>
        /// compare records based on num_accounts
        /// is int compare on Num_accounts property of Activity report record
        /// </summary>
        private class ActivityNumAccountsComparer : IComparer<ActivityReportRecord>
        {
            int IComparer<ActivityReportRecord>.Compare(ActivityReportRecord x, ActivityReportRecord y)
            {
                if (x == null && y == null) return 0;
                else if (x == null) return -1;
                else if (y == null) return 1;
                if (x == y) return 0;

                return x.Num_accounts.CompareTo(y.Num_accounts);
            }
        }

        /// <summary>
        /// compare records based on count_1_day_actives
        /// is int compare on Count_1_day_actives property of Activity report record
        /// </summary>
        private class Activity1DayActivesComparer : IComparer<ActivityReportRecord>
        {
            int IComparer<ActivityReportRecord>.Compare(ActivityReportRecord x, ActivityReportRecord y)
            {
                if (x == null && y == null) return 0;
                else if (x == null) return -1;
                else if (y == null) return 1;
                if (x == y) return 0;

                return x.Count_1_day_actives.CompareTo(y.Count_1_day_actives);
            }
        }

        /// <summary>
        /// compare records based on count_7_day_actives
        /// is int compare on Count_7_day_actives property of Activity report record
        /// </summary>
        private class Activity7DayActivesComparer : IComparer<ActivityReportRecord>
        {
            int IComparer<ActivityReportRecord>.Compare(ActivityReportRecord x, ActivityReportRecord y)
            {
                if (x == null && y == null) return 0;
                else if (x == null) return -1;
                else if (y == null) return 1;
                if (x == y) return 0;

                return x.Count_7_day_actives.CompareTo(y.Count_7_day_actives);
            }
        }

        /// <summary>
        /// compare records based on count_14_day_actives
        /// is int compare on Count_14_day_actives property of Activity report record
        /// </summary>
        private class Activity14DayActivesComparer : IComparer<ActivityReportRecord>
        {
            int IComparer<ActivityReportRecord>.Compare(ActivityReportRecord x, ActivityReportRecord y)
            {
                if (x == null && y == null) return 0;
                else if (x == null) return -1;
                else if (y == null) return 1;
                if (x == y) return 0;

                return x.Count_14_day_actives.CompareTo(y.Count_14_day_actives);
            }
        }

        /// <summary>
        /// compare records based on count_30_day_actives
        /// is int compare on Count_30_day_actives property of Activity report record
        /// </summary>
        private class Activity30DayActivesComparer : IComparer<ActivityReportRecord>
        {
            int IComparer<ActivityReportRecord>.Compare(ActivityReportRecord x, ActivityReportRecord y)
            {
                if (x == null && y == null) return 0;
                else if (x == null) return -1;
                else if (y == null) return 1;
                if (x == y) return 0;

                return x.Count_30_day_actives.CompareTo(y.Count_30_day_actives);
            }
        }

        /// <summary>
        /// compare records based on count_30_day_idle
        /// is int compare on Count_30_day_idle property of Activity report record
        /// </summary>
        private class Activity30DayIdleComparer : IComparer<ActivityReportRecord>
        {
            int IComparer<ActivityReportRecord>.Compare(ActivityReportRecord x, ActivityReportRecord y)
            {
                if (x == null && y == null) return 0;
                else if (x == null) return -1;
                else if (y == null) return 1;
                if (x == y) return 0;

                return x.Count_30_day_idle.CompareTo(y.Count_30_day_idle);
            }
        }

        /// <summary>
        /// compare records based on count_60_day_idle
        /// is int compare on Count_60_day_idle property of Activity report record
        /// </summary>
        private class Activity60DayIdleComparer : IComparer<ActivityReportRecord>
        {
            int IComparer<ActivityReportRecord>.Compare(ActivityReportRecord x, ActivityReportRecord y)
            {
                if (x == null && y == null) return 0;
                else if (x == null) return -1;
                else if (y == null) return 1;
                if (x == y) return 0;

                return x.Count_60_day_idle.CompareTo(y.Count_60_day_idle);
            }
        }

        /// <summary>
        /// compare records based on count_90_day_idle
        /// is int compare on Count_90_day_idle property of Activity report record
        /// </summary>
        private class Activity90DayIdleComparer : IComparer<ActivityReportRecord>
        {
            int IComparer<ActivityReportRecord>.Compare(ActivityReportRecord x, ActivityReportRecord y)
            {
                if (x == null && y == null) return 0;
                else if (x == null) return -1;
                else if (y == null) return 1;
                if (x == y) return 0;

                return x.Count_90_day_idle.CompareTo(y.Count_90_day_idle);
            }
        }

        #endregion

        #region internal variables

        private int _Num_accounts;
        private int _Count_1_day_actives;
        private int _Count_7_day_actives;
        private int _Count_14_day_actives;
        private int _Count_30_day_actives;
        private int _Count_30_day_idle;
        private int _Count_60_day_idle;
        private int _Count_90_day_idle;

        #endregion

        #region properties
        /// <summary>
        /// The num_accounts field specifies the total number of user-accessible accounts in your domain. An account is considered 
        /// user-accessible unless you have suspended access to the account or account access has been suspended due to abuse or complaints
        /// </summary>
        public int Num_accounts { get { return _Num_accounts; } set { _Num_accounts = value; } }

        /// <summary>
        /// The count_1_day_actives field identifies the number of hosted accounts in your domain that were active within the previous day.
        /// An account that is counted in the count_1_day_actives column will also be counted in the count_7_day_actives, 
        /// count_14_day_actives and count_30_day_actives columns.
        /// </summary>
        public int Count_1_day_actives { get { return _Count_1_day_actives; } set { _Count_1_day_actives = value; } }

        /// <summary>
        /// The count_7_day_actives field identifies the number of hosted accounts in your domain that were active within the previous seven days.
        /// An account that is counted in the count_7_day_actives column will also be counted in the count_14_day_actives and count_30_day_actives 
        /// columns and may also be counted in the count_1_day_actives column, depending on the date the account was most recently accessed.
        /// </summary>
        public int Count_7_day_actives { get { return _Count_7_day_actives; } set { _Count_7_day_actives = value; } }

        /// <summary>
        /// The count_14_day_actives field identifies the number of hosted accounts in your domain that were active within the previous 14 days.
        /// An account that is counted in the count_14_day_actives column will also be counted in the count_30_day_actives column and may also be 
        /// counted in the count_1_day_actives and count_7_day_actives columns, depending on the date the account was most recently accessed.
        /// </summary>
        public int Count_14_day_actives { get { return _Count_14_day_actives; } set { _Count_14_day_actives = value; } }

        /// <summary>
        /// The count_30_day_actives field identifies the number of hosted accounts in your domain that were active within the previous thirty days.
        /// An account that is counted in the count_30_day_actives column may also be counted in the count_1_day_actives and count_7_day_actives and 
        /// count_14_day_actives columns, depending on the date the account was most recently accessed.
        /// </summary>
        public int Count_30_day_actives { get { return _Count_30_day_actives; } set { _Count_30_day_actives = value; } }

        /// <summary>
        /// The count_30_day_idle field specifies the number of hosted accounts in your domain that have been idle for 30 to 59 days. 
        /// An account is idle as long as there has been no user activity for the account.
        /// </summary>
        public int Count_30_day_idle { get { return _Count_30_day_idle; } set { _Count_30_day_idle = value; } }

        /// <summary>
        /// The count_60_day_idle field specifies the number of hosted accounts in your domain that have been idle for 60 to 89 days. An account is idle 
        /// as long as there has been no user activity for the account.
        /// </summary>
        public int Count_60_day_idle { get { return _Count_60_day_idle; } set { _Count_60_day_idle = value; } }

        /// <summary>
        /// The count_90_day_idle field specifies the number of hosted accounts in your domain that have been idle for 90 days or more. An account is idle 
        /// as long as there has been no user activity for the account.
        /// </summary>
        public int Count_90_day_idle { get { return _Count_90_day_idle; } set { _Count_90_day_idle = value; } }

        #endregion
    }

    /// <summary>
    /// he disk_space report shows the amount of disk space occupied by users' mailboxes. The report identifies the total number of accounts in your domain
    /// as well as the number of accounts that fall into several different size groupings. Mailboxes that occupy less than 1GB of disk space are grouped in 
    /// increments of 100MB, and mailboxes that occupy between 1GB and 10GB of disk space are grouped in increments of 500MB.
    /// </summary>
    public class DiskSpaceReportRecord : Google.Apps.Reporting.ReportRecord
    {
        #region overrides
        /// <summary>
        /// returns string of report record in format that like that originally delivered in report query
        /// </summary>
        /// <returns>report record in format that like that originally delivered in report query</returns>
        public override string ToString()
        {
            /**
             * date,num_accounts,usage_in_bytes,avg_usage_in_mb,quota_in_mb,avg_quota_in_mb,size_0.1gb,size_0.2gb,size_0.3gb,size_0.4gb,size_0.5gb,size_0.6gb,
             * size_0.7gb,size_0.8gb,size_0.9gb,size_1.0gb,size_1.5gb,size_2.0gb,size_2.5gb,size_3.0gb,size_3.5gb,size_4.0gb,size_4.5gb,size_5.0gb,size_5.5gb,
             * size_6.0gb,size_6.5gb,size_7.0gb,size_7.5gb,size_8.0gb,size_8.5gb,size_9.0gb,size_9.5gb,size_10.0gb
             **/

            return this.Date.ToString("yyyyMMdd") + "," + this.Usage_in_bytes + "," + this.Avg_usage_in_mb + "," + this.Quota_in_mb + "," + this.Avg_quota_in_mb
                + "," + this.Size_0_1gb + "," + this.Size_0_2gb + "," + this.Size_0_3gb + "," + this.Size_0_4gb + "," + this.Size_0_5gb + "," + this.Size_0_6gb
                + "," + this.Size_0_7gb + "," + this.Size_0_8gb + "," + this.Size_0_9gb + "," + this.Size_1_0gb + "," + this.Size_1_5gb + "," + this.Size_2_0gb
                + "," + this.Size_2_5gb + "," + this.Size_3_0gb + "," + this.Size_3_5gb + "," + this.Size_4_0gb + "," + this.Size_4_5gb + "," + this.Size_5_0gb
                + "," + this.Size_5_5gb + "," + this.Size_6_0gb + "," + this.Size_6_5gb + "," + this.Size_7_0gb + "," + this.Size_7_5gb + "," + this.Size_8_0gb
                + "," + this.Size_8_5gb + "," + this.Size_9_0gb + "," + this.Size_9_5gb + "," + this.Size_10_0gb;
        }

        #endregion

        #region instantiation

        /// <summary>
        /// default instantiation
        /// </summary>
        public DiskSpaceReportRecord() { }

        /// <summary>
        /// parses string from google report.  
        /// API v1.0.1 this will be a comma delimited string
        /// </summary>
        /// <param name="googleReturnedReportRecordString">date,num_accounts,usage_in_bytes,avg_usage_in_mb,quota_in_mb,avg_quota_in_mb,size_0.1gb,size_0.2gb,
        /// size_0.3gb,size_0.4gb,size_0.5gb,size_0.6gb,size_0.7gb,size_0.8gb,size_0.9gb,size_1.0gb,size_1.5gb,size_2.0gb,size_2.5gb,size_3.0gb,size_3.5gb,
        /// size_4.0gb,size_4.5gb,size_5.0gb,size_5.5gb,size_6.0gb,size_6.5gb,size_7.0gb,size_7.5gb,size_8.0gb,size_8.5gb,size_9.0gb,size_9.5gb,size_10.0gb</param>
        public DiskSpaceReportRecord(string googleReturnedReportRecordString)
        {
            int expectedSplitLength = 34; // API v1.0.1 disk space report record
            string[] split = null;
            int currentPos = 0;  //track split during assignment for error

            try
            {
                split = googleReturnedReportRecordString.Split(',');
            }
            catch (Exception)
            {
                throw new FormatException("cannot split passed string in report record instantiation from google reporting returned string");
            }

            if (split.Length != expectedSplitLength)
            {
                throw new FormatException("passed string split to array of non-expected size - seen: " + split.Length + " expected: " + expectedSplitLength);
            }



            try
            {
                this._Date = new DateTime(Convert.ToInt32(split[0].Substring(0, 4)), Convert.ToInt32(split[0].Substring(4, 2)), Convert.ToInt32(split[0].Substring(6, 2))); currentPos++;
                this._Num_accounts = Convert.ToInt32(split[1]); currentPos++;
                this._Usage_in_bytes = Convert.ToInt32(split[2]); currentPos++;
                this._Avg_usage_in_mb = Convert.ToInt32(split[3]); currentPos++;
                this._Quota_in_mb = Convert.ToInt32(split[4]); currentPos++;
                this._Avg_quota_in_mb = Convert.ToInt32(split[5]); currentPos++;
                this._Size_0_1gb = Convert.ToInt32(split[6]); currentPos++;
                this._Size_0_2gb = Convert.ToInt32(split[7]); currentPos++;
                this._Size_0_3gb = Convert.ToInt32(split[8]); currentPos++;
                this._Size_0_4gb = Convert.ToInt32(split[9]); currentPos++;
                this._Size_0_5gb = Convert.ToInt32(split[10]); currentPos++;
                this._Size_0_6gb = Convert.ToInt32(split[11]); currentPos++;
                this._Size_0_7gb = Convert.ToInt32(split[12]); currentPos++;
                this._Size_0_8gb = Convert.ToInt32(split[13]); currentPos++;
                this._Size_0_9gb = Convert.ToInt32(split[14]); currentPos++;
                this._Size_1_0gb = Convert.ToInt32(split[15]); currentPos++;
                this._Size_1_5gb = Convert.ToInt32(split[16]); currentPos++;
                this._Size_2_0gb = Convert.ToInt32(split[17]); currentPos++;
                this._Size_2_5gb = Convert.ToInt32(split[18]); currentPos++;
                this._Size_3_0gb = Convert.ToInt32(split[19]); currentPos++;
                this._Size_3_5gb = Convert.ToInt32(split[20]); currentPos++;
                this._Size_4_0gb = Convert.ToInt32(split[21]); currentPos++;
                this._Size_4_5gb = Convert.ToInt32(split[22]); currentPos++;
                this._Size_5_0gb = Convert.ToInt32(split[23]); currentPos++;
                this._Size_5_5gb = Convert.ToInt32(split[24]); currentPos++;
                this._Size_6_0gb = Convert.ToInt32(split[25]); currentPos++;
                this._Size_6_5gb = Convert.ToInt32(split[26]); currentPos++;
                this._Size_7_0gb = Convert.ToInt32(split[27]); currentPos++;
                this._Size_7_5gb = Convert.ToInt32(split[28]); currentPos++;
                this._Size_8_0gb = Convert.ToInt32(split[29]); currentPos++;
                this._Size_8_5gb = Convert.ToInt32(split[30]); currentPos++;
                this._Size_9_0gb = Convert.ToInt32(split[31]); currentPos++;
                this._Size_9_5gb = Convert.ToInt32(split[32]); currentPos++;
                this._Size_10_0gb = Convert.ToInt32(split[33]);
            }
            catch (Exception) { throw new FormatException("could not parse from data: " + split[currentPos]); }
        }

        #endregion

        #region comparers

        public static IComparer<DiskSpaceReportRecord> DiskSpaceNumAccountsSorter { get { return new DiskSpaceNumAccountsComparer(); } }
        public static IComparer<DiskSpaceReportRecord> DiskSpaceUsageInBytesSorter { get { return new DiskSpaceUsageInBytesComparer(); } }
        public static IComparer<DiskSpaceReportRecord> DiskSpaceAvgUsageInMBSorter { get { return new DiskSpaceAvgUsageInMBComparer(); } }
        public static IComparer<DiskSpaceReportRecord> DiskSpaceQuotaInMBSorter { get { return new DiskSpaceQuotaInMBComparer(); } }
        public static IComparer<DiskSpaceReportRecord> DiskSpaceAvgQuotaInMBSorter { get { return new DiskSpaceAvgQuotaInMBComparer(); } }
        public static IComparer<DiskSpaceReportRecord> DiskSpaceSize0_1Sorter { get { return new DiskSpaceSize0_1Comparer(); } }
        public static IComparer<DiskSpaceReportRecord> DiskSpaceSize0_2Sorter { get { return new DiskSpaceSize0_2Comparer(); } }
        public static IComparer<DiskSpaceReportRecord> DiskSpaceSize0_3Sorter { get { return new DiskSpaceSize0_3Comparer(); } }
        public static IComparer<DiskSpaceReportRecord> DiskSpaceSize0_4Sorter { get { return new DiskSpaceSize0_4Comparer(); } }
        public static IComparer<DiskSpaceReportRecord> DiskSpaceSize0_5Sorter { get { return new DiskSpaceSize0_5Comparer(); } }
        public static IComparer<DiskSpaceReportRecord> DiskSpaceSize0_6Sorter { get { return new DiskSpaceSize0_6Comparer(); } }
        public static IComparer<DiskSpaceReportRecord> DiskSpaceSize0_7Sorter { get { return new DiskSpaceSize0_7Comparer(); } }
        public static IComparer<DiskSpaceReportRecord> DiskSpaceSize0_8Sorter { get { return new DiskSpaceSize0_8Comparer(); } }
        public static IComparer<DiskSpaceReportRecord> DiskSpaceSize0_9Sorter { get { return new DiskSpaceSize0_9Comparer(); } }
        public static IComparer<DiskSpaceReportRecord> DiskSpaceSize1_0Sorter { get { return new DiskSpaceSize1_0Comparer(); } }
        public static IComparer<DiskSpaceReportRecord> DiskSpaceSize1_5Sorter { get { return new DiskSpaceSize1_5Comparer(); } }
        public static IComparer<DiskSpaceReportRecord> DiskSpaceSize2_0Sorter { get { return new DiskSpaceSize2_0Comparer(); } }
        public static IComparer<DiskSpaceReportRecord> DiskSpaceSize2_5Sorter { get { return new DiskSpaceSize2_5Comparer(); } }
        public static IComparer<DiskSpaceReportRecord> DiskSpaceSize3_0Sorter { get { return new DiskSpaceSize3_0Comparer(); } }
        public static IComparer<DiskSpaceReportRecord> DiskSpaceSize3_5Sorter { get { return new DiskSpaceSize3_5Comparer(); } }
        public static IComparer<DiskSpaceReportRecord> DiskSpaceSize4_0Sorter { get { return new DiskSpaceSize4_0Comparer(); } }
        public static IComparer<DiskSpaceReportRecord> DiskSpaceSize4_5Sorter { get { return new DiskSpaceSize4_5Comparer(); } }
        public static IComparer<DiskSpaceReportRecord> DiskSpaceSize5_0Sorter { get { return new DiskSpaceSize5_0Comparer(); } }
        public static IComparer<DiskSpaceReportRecord> DiskSpaceSize5_5Sorter { get { return new DiskSpaceSize5_5Comparer(); } }
        public static IComparer<DiskSpaceReportRecord> DiskSpaceSize6_0Sorter { get { return new DiskSpaceSize6_0Comparer(); } }
        public static IComparer<DiskSpaceReportRecord> DiskSpaceSize6_5Sorter { get { return new DiskSpaceSize6_5Comparer(); } }
        public static IComparer<DiskSpaceReportRecord> DiskSpaceSize7_0Sorter { get { return new DiskSpaceSize7_0Comparer(); } }
        public static IComparer<DiskSpaceReportRecord> DiskSpaceSize7_5Sorter { get { return new DiskSpaceSize7_5Comparer(); } }
        public static IComparer<DiskSpaceReportRecord> DiskSpaceSize8_0Sorter { get { return new DiskSpaceSize8_0Comparer(); } }
        public static IComparer<DiskSpaceReportRecord> DiskSpaceSize8_5Sorter { get { return new DiskSpaceSize8_5Comparer(); } }
        public static IComparer<DiskSpaceReportRecord> DiskSpaceSize9_0Sorter { get { return new DiskSpaceSize9_0Comparer(); } }
        public static IComparer<DiskSpaceReportRecord> DiskSpaceSize9_5Sorter { get { return new DiskSpaceSize9_5Comparer(); } }
        public static IComparer<DiskSpaceReportRecord> DiskSpaceSize10_0Sorter { get { return new DiskSpaceSize10_0Comparer(); } }

        /// <summary>
        /// compare records based on num_accounts
        /// is int compare on Num_accounts property of DiskSpace report record
        /// </summary>
        private class DiskSpaceNumAccountsComparer : IComparer<DiskSpaceReportRecord>
        {
            int IComparer<DiskSpaceReportRecord>.Compare(DiskSpaceReportRecord x, DiskSpaceReportRecord y)
            {
                if (x == null && y == null) return 0;
                else if (x == null) return -1;
                else if (y == null) return 1;
                if (x == y) return 0;

                return x.Num_accounts.CompareTo(y.Num_accounts);
            }
        }

        /// <summary>
        /// compare records based on usage_in_bytes
        /// is int compare on Usage_in_bytes property of DiskSpace report record
        /// </summary>
        private class DiskSpaceUsageInBytesComparer : IComparer<DiskSpaceReportRecord>
        {
            int IComparer<DiskSpaceReportRecord>.Compare(DiskSpaceReportRecord x, DiskSpaceReportRecord y)
            {
                if (x == null && y == null) return 0;
                else if (x == null) return -1;
                else if (y == null) return 1;
                if (x == y) return 0;

                return x.Usage_in_bytes.CompareTo(y.Usage_in_bytes);
            }
        }

        /// <summary>
        /// compare records based on avg_usage_in_mb
        /// is int compare on Avg_usage_in_mb property of DiskSpace report record
        /// </summary>
        private class DiskSpaceAvgUsageInMBComparer : IComparer<DiskSpaceReportRecord>
        {
            int IComparer<DiskSpaceReportRecord>.Compare(DiskSpaceReportRecord x, DiskSpaceReportRecord y)
            {
                if (x == null && y == null) return 0;
                else if (x == null) return -1;
                else if (y == null) return 1;
                if (x == y) return 0;

                return x.Avg_usage_in_mb.CompareTo(y.Avg_usage_in_mb);
            }
        }

        /// <summary>
        /// compare records based on quota_in_mb
        /// is int compare on Qutoa_in_mb property of DiskSpace report record
        /// </summary>
        private class DiskSpaceQuotaInMBComparer : IComparer<DiskSpaceReportRecord>
        {
            int IComparer<DiskSpaceReportRecord>.Compare(DiskSpaceReportRecord x, DiskSpaceReportRecord y)
            {
                if (x == null && y == null) return 0;
                else if (x == null) return -1;
                else if (y == null) return 1;
                if (x == y) return 0;

                return x.Quota_in_mb.CompareTo(y.Quota_in_mb);
            }
        }

        /// <summary>
        /// compare records based on avg_quota_in_mb
        /// is int compare on Avg_quota_in_mb property of DiskSpace report record
        /// </summary>
        private class DiskSpaceAvgQuotaInMBComparer : IComparer<DiskSpaceReportRecord>
        {
            int IComparer<DiskSpaceReportRecord>.Compare(DiskSpaceReportRecord x, DiskSpaceReportRecord y)
            {
                if (x == null && y == null) return 0;
                else if (x == null) return -1;
                else if (y == null) return 1;
                if (x == y) return 0;

                return x.Avg_quota_in_mb.CompareTo(y.Avg_quota_in_mb);
            }
        }


        /// <summary>
        /// compare records based on size_0.1
        /// is int compare on Size_0_1 property of DiskSpace report record
        /// </summary>
        private class DiskSpaceSize0_1Comparer : IComparer<DiskSpaceReportRecord>
        {
            int IComparer<DiskSpaceReportRecord>.Compare(DiskSpaceReportRecord x, DiskSpaceReportRecord y)
            {
                if (x == null && y == null) return 0;
                else if (x == null) return -1;
                else if (y == null) return 1;
                if (x == y) return 0;

                return x.Size_0_1gb.CompareTo(y.Size_0_1gb);
            }
        }

        /// <summary>
        /// compare records based on size_0.2
        /// is int compare on Size_0_2 property of DiskSpace report record
        /// </summary>
        private class DiskSpaceSize0_2Comparer : IComparer<DiskSpaceReportRecord>
        {
            int IComparer<DiskSpaceReportRecord>.Compare(DiskSpaceReportRecord x, DiskSpaceReportRecord y)
            {
                if (x == null && y == null) return 0;
                else if (x == null) return -1;
                else if (y == null) return 1;
                if (x == y) return 0;

                return x.Size_0_2gb.CompareTo(y.Size_0_2gb);
            }
        }

        /// <summary>
        /// compare records based on size_0.3
        /// is int compare on Size_0_3 property of DiskSpace report record
        /// </summary>
        private class DiskSpaceSize0_3Comparer : IComparer<DiskSpaceReportRecord>
        {
            int IComparer<DiskSpaceReportRecord>.Compare(DiskSpaceReportRecord x, DiskSpaceReportRecord y)
            {
                if (x == null && y == null) return 0;
                else if (x == null) return -1;
                else if (y == null) return 1;
                if (x == y) return 0;

                return x.Size_0_3gb.CompareTo(y.Size_0_3gb);
            }
        }

        /// <summary>
        /// compare records based on size_0.4
        /// is int compare on Size_0_4 property of DiskSpace report record
        /// </summary>
        private class DiskSpaceSize0_4Comparer : IComparer<DiskSpaceReportRecord>
        {
            int IComparer<DiskSpaceReportRecord>.Compare(DiskSpaceReportRecord x, DiskSpaceReportRecord y)
            {
                if (x == null && y == null) return 0;
                else if (x == null) return -1;
                else if (y == null) return 1;
                if (x == y) return 0;

                return x.Size_0_4gb.CompareTo(y.Size_0_4gb);
            }
        }

        /// <summary>
        /// compare records based on size_0.5
        /// is int compare on Size_0_5 property of DiskSpace report record
        /// </summary>
        private class DiskSpaceSize0_5Comparer : IComparer<DiskSpaceReportRecord>
        {
            int IComparer<DiskSpaceReportRecord>.Compare(DiskSpaceReportRecord x, DiskSpaceReportRecord y)
            {
                if (x == null && y == null) return 0;
                else if (x == null) return -1;
                else if (y == null) return 1;
                if (x == y) return 0;

                return x.Size_0_5gb.CompareTo(y.Size_0_5gb);
            }
        }

        /// <summary>
        /// compare records based on size_0.6
        /// is int compare on Size_0_6 property of DiskSpace report record
        /// </summary>
        private class DiskSpaceSize0_6Comparer : IComparer<DiskSpaceReportRecord>
        {
            int IComparer<DiskSpaceReportRecord>.Compare(DiskSpaceReportRecord x, DiskSpaceReportRecord y)
            {
                if (x == null && y == null) return 0;
                else if (x == null) return -1;
                else if (y == null) return 1;
                if (x == y) return 0;

                return x.Size_0_6gb.CompareTo(y.Size_0_6gb);
            }
        }

        /// <summary>
        /// compare records based on size_0.7
        /// is int compare on Size_0_7 property of DiskSpace report record
        /// </summary>
        private class DiskSpaceSize0_7Comparer : IComparer<DiskSpaceReportRecord>
        {
            int IComparer<DiskSpaceReportRecord>.Compare(DiskSpaceReportRecord x, DiskSpaceReportRecord y)
            {
                if (x == null && y == null) return 0;
                else if (x == null) return -1;
                else if (y == null) return 1;
                if (x == y) return 0;

                return x.Size_0_7gb.CompareTo(y.Size_0_7gb);
            }
        }

        /// <summary>
        /// compare records based on size_0.8
        /// is int compare on Size_0_8 property of DiskSpace report record
        /// </summary>
        private class DiskSpaceSize0_8Comparer : IComparer<DiskSpaceReportRecord>
        {
            int IComparer<DiskSpaceReportRecord>.Compare(DiskSpaceReportRecord x, DiskSpaceReportRecord y)
            {
                if (x == null && y == null) return 0;
                else if (x == null) return -1;
                else if (y == null) return 1;
                if (x == y) return 0;

                return x.Size_0_8gb.CompareTo(y.Size_0_8gb);
            }
        }
        /// <summary>
        /// compare records based on size_0.9
        /// is int compare on Size_0_9 property of DiskSpace report record
        /// </summary>
        private class DiskSpaceSize0_9Comparer : IComparer<DiskSpaceReportRecord>
        {
            int IComparer<DiskSpaceReportRecord>.Compare(DiskSpaceReportRecord x, DiskSpaceReportRecord y)
            {
                if (x == null && y == null) return 0;
                else if (x == null) return -1;
                else if (y == null) return 1;
                if (x == y) return 0;

                return x.Size_0_9gb.CompareTo(y.Size_0_9gb);
            }
        }

        /// <summary>
        /// compare records based on size_1.0
        /// is int compare on Size_1_0 property of DiskSpace report record
        /// </summary>
        private class DiskSpaceSize1_0Comparer : IComparer<DiskSpaceReportRecord>
        {
            int IComparer<DiskSpaceReportRecord>.Compare(DiskSpaceReportRecord x, DiskSpaceReportRecord y)
            {
                if (x == null && y == null) return 0;
                else if (x == null) return -1;
                else if (y == null) return 1;
                if (x == y) return 0;

                return x.Size_1_0gb.CompareTo(y.Size_1_0gb);
            }
        }

        /// <summary>
        /// compare records based on size_1.5
        /// is int compare on Size_1_5 property of DiskSpace report record
        /// </summary>
        private class DiskSpaceSize1_5Comparer : IComparer<DiskSpaceReportRecord>
        {
            int IComparer<DiskSpaceReportRecord>.Compare(DiskSpaceReportRecord x, DiskSpaceReportRecord y)
            {
                if (x == null && y == null) return 0;
                else if (x == null) return -1;
                else if (y == null) return 1;
                if (x == y) return 0;

                return x.Size_1_5gb.CompareTo(y.Size_1_5gb);
            }
        }

        /// <summary>
        /// compare records based on size_2.0
        /// is int compare on Size_2_0 property of DiskSpace report record
        /// </summary>
        private class DiskSpaceSize2_0Comparer : IComparer<DiskSpaceReportRecord>
        {
            int IComparer<DiskSpaceReportRecord>.Compare(DiskSpaceReportRecord x, DiskSpaceReportRecord y)
            {
                if (x == null && y == null) return 0;
                else if (x == null) return -1;
                else if (y == null) return 1;
                if (x == y) return 0;

                return x.Size_2_0gb.CompareTo(y.Size_2_0gb);
            }
        }

        /// <summary>
        /// compare records based on size_2.5
        /// is int compare on Size_2_5 property of DiskSpace report record
        /// </summary>
        private class DiskSpaceSize2_5Comparer : IComparer<DiskSpaceReportRecord>
        {
            int IComparer<DiskSpaceReportRecord>.Compare(DiskSpaceReportRecord x, DiskSpaceReportRecord y)
            {
                if (x == null && y == null) return 0;
                else if (x == null) return -1;
                else if (y == null) return 1;
                if (x == y) return 0;

                return x.Size_2_5gb.CompareTo(y.Size_2_5gb);
            }
        }

        /// <summary>
        /// compare records based on size_3.0
        /// is int compare on Size_3_0 property of DiskSpace report record
        /// </summary>
        private class DiskSpaceSize3_0Comparer : IComparer<DiskSpaceReportRecord>
        {
            int IComparer<DiskSpaceReportRecord>.Compare(DiskSpaceReportRecord x, DiskSpaceReportRecord y)
            {
                if (x == null && y == null) return 0;
                else if (x == null) return -1;
                else if (y == null) return 1;
                if (x == y) return 0;

                return x.Size_3_0gb.CompareTo(y.Size_3_0gb);
            }
        }

        /// <summary>
        /// compare records based on size_3.5
        /// is int compare on Size_3_5 property of DiskSpace report record
        /// </summary>
        private class DiskSpaceSize3_5Comparer : IComparer<DiskSpaceReportRecord>
        {
            int IComparer<DiskSpaceReportRecord>.Compare(DiskSpaceReportRecord x, DiskSpaceReportRecord y)
            {
                if (x == null && y == null) return 0;
                else if (x == null) return -1;
                else if (y == null) return 1;
                if (x == y) return 0;

                return x.Size_3_5gb.CompareTo(y.Size_3_5gb);
            }
        }

        /// <summary>
        /// compare records based on size_4.0
        /// is int compare on Size_4_0 property of DiskSpace report record
        /// </summary>
        private class DiskSpaceSize4_0Comparer : IComparer<DiskSpaceReportRecord>
        {
            int IComparer<DiskSpaceReportRecord>.Compare(DiskSpaceReportRecord x, DiskSpaceReportRecord y)
            {
                if (x == null && y == null) return 0;
                else if (x == null) return -1;
                else if (y == null) return 1;
                if (x == y) return 0;

                return x.Size_4_0gb.CompareTo(y.Size_4_0gb);
            }
        }

        /// <summary>
        /// compare records based on size_4.5
        /// is int compare on Size_4_5 property of DiskSpace report record
        /// </summary>
        private class DiskSpaceSize4_5Comparer : IComparer<DiskSpaceReportRecord>
        {
            int IComparer<DiskSpaceReportRecord>.Compare(DiskSpaceReportRecord x, DiskSpaceReportRecord y)
            {
                if (x == null && y == null) return 0;
                else if (x == null) return -1;
                else if (y == null) return 1;
                if (x == y) return 0;

                return x.Size_4_5gb.CompareTo(y.Size_4_5gb);
            }
        }

        /// <summary>
        /// compare records based on size_5.0
        /// is int compare on Size_5_0 property of DiskSpace report record
        /// </summary>
        private class DiskSpaceSize5_0Comparer : IComparer<DiskSpaceReportRecord>
        {
            int IComparer<DiskSpaceReportRecord>.Compare(DiskSpaceReportRecord x, DiskSpaceReportRecord y)
            {
                if (x == null && y == null) return 0;
                else if (x == null) return -1;
                else if (y == null) return 1;
                if (x == y) return 0;

                return x.Size_5_0gb.CompareTo(y.Size_5_0gb);
            }
        }

        /// <summary>
        /// compare records based on size_5.5
        /// is int compare on Size_5_5 property of DiskSpace report record
        /// </summary>
        private class DiskSpaceSize5_5Comparer : IComparer<DiskSpaceReportRecord>
        {
            int IComparer<DiskSpaceReportRecord>.Compare(DiskSpaceReportRecord x, DiskSpaceReportRecord y)
            {
                if (x == null && y == null) return 0;
                else if (x == null) return -1;
                else if (y == null) return 1;
                if (x == y) return 0;

                return x.Size_5_5gb.CompareTo(y.Size_5_5gb);
            }
        }

        /// <summary>
        /// compare records based on size_6.0
        /// is int compare on Size_6_0 property of DiskSpace report record
        /// </summary>
        private class DiskSpaceSize6_0Comparer : IComparer<DiskSpaceReportRecord>
        {
            int IComparer<DiskSpaceReportRecord>.Compare(DiskSpaceReportRecord x, DiskSpaceReportRecord y)
            {
                if (x == null && y == null) return 0;
                else if (x == null) return -1;
                else if (y == null) return 1;
                if (x == y) return 0;

                return x.Size_6_0gb.CompareTo(y.Size_6_0gb);
            }
        }

        /// <summary>
        /// compare records based on size_6.5
        /// is int compare on Size_6_5 property of DiskSpace report record
        /// </summary>
        private class DiskSpaceSize6_5Comparer : IComparer<DiskSpaceReportRecord>
        {
            int IComparer<DiskSpaceReportRecord>.Compare(DiskSpaceReportRecord x, DiskSpaceReportRecord y)
            {
                if (x == null && y == null) return 0;
                else if (x == null) return -1;
                else if (y == null) return 1;
                if (x == y) return 0;

                return x.Size_6_5gb.CompareTo(y.Size_6_5gb);
            }
        }

        /// <summary>
        /// compare records based on size_7.0
        /// is int compare on Size_7_0 property of DiskSpace report record
        /// </summary>
        private class DiskSpaceSize7_0Comparer : IComparer<DiskSpaceReportRecord>
        {
            int IComparer<DiskSpaceReportRecord>.Compare(DiskSpaceReportRecord x, DiskSpaceReportRecord y)
            {
                if (x == null && y == null) return 0;
                else if (x == null) return -1;
                else if (y == null) return 1;
                if (x == y) return 0;

                return x.Size_7_0gb.CompareTo(y.Size_7_0gb);
            }
        }

        /// <summary>
        /// compare records based on size_7.5
        /// is int compare on Size_7_5 property of DiskSpace report record
        /// </summary>
        private class DiskSpaceSize7_5Comparer : IComparer<DiskSpaceReportRecord>
        {
            int IComparer<DiskSpaceReportRecord>.Compare(DiskSpaceReportRecord x, DiskSpaceReportRecord y)
            {
                if (x == null && y == null) return 0;
                else if (x == null) return -1;
                else if (y == null) return 1;
                if (x == y) return 0;

                return x.Size_7_5gb.CompareTo(y.Size_7_5gb);
            }
        }

        /// <summary>
        /// compare records based on size_8.0
        /// is int compare on Size_8_0 property of DiskSpace report record
        /// </summary>
        private class DiskSpaceSize8_0Comparer : IComparer<DiskSpaceReportRecord>
        {
            int IComparer<DiskSpaceReportRecord>.Compare(DiskSpaceReportRecord x, DiskSpaceReportRecord y)
            {
                if (x == null && y == null) return 0;
                else if (x == null) return -1;
                else if (y == null) return 1;
                if (x == y) return 0;

                return x.Size_8_0gb.CompareTo(y.Size_8_0gb);
            }
        }

        /// <summary>
        /// compare records based on size_8.5
        /// is int compare on Size_8_5 property of DiskSpace report record
        /// </summary>
        private class DiskSpaceSize8_5Comparer : IComparer<DiskSpaceReportRecord>
        {
            int IComparer<DiskSpaceReportRecord>.Compare(DiskSpaceReportRecord x, DiskSpaceReportRecord y)
            {
                if (x == null && y == null) return 0;
                else if (x == null) return -1;
                else if (y == null) return 1;
                if (x == y) return 0;

                return x.Size_8_5gb.CompareTo(y.Size_8_5gb);
            }
        }

        /// <summary>
        /// compare records based on size_9.0
        /// is int compare on Size_9_0 property of DiskSpace report record
        /// </summary>
        private class DiskSpaceSize9_0Comparer : IComparer<DiskSpaceReportRecord>
        {
            int IComparer<DiskSpaceReportRecord>.Compare(DiskSpaceReportRecord x, DiskSpaceReportRecord y)
            {
                if (x == null && y == null) return 0;
                else if (x == null) return -1;
                else if (y == null) return 1;
                if (x == y) return 0;

                return x.Size_9_0gb.CompareTo(y.Size_9_0gb);
            }
        }

        /// <summary>
        /// compare records based on size_9.5
        /// is int compare on Size_9_5 property of DiskSpace report record
        /// </summary>
        private class DiskSpaceSize9_5Comparer : IComparer<DiskSpaceReportRecord>
        {
            int IComparer<DiskSpaceReportRecord>.Compare(DiskSpaceReportRecord x, DiskSpaceReportRecord y)
            {
                if (x == null && y == null) return 0;
                else if (x == null) return -1;
                else if (y == null) return 1;
                if (x == y) return 0;

                return x.Size_9_5gb.CompareTo(y.Size_9_5gb);
            }
        }

        /// <summary>
        /// compare records based on size_10.0
        /// is int compare on Size_10_0 property of DiskSpace report record
        /// </summary>
        private class DiskSpaceSize10_0Comparer : IComparer<DiskSpaceReportRecord>
        {
            int IComparer<DiskSpaceReportRecord>.Compare(DiskSpaceReportRecord x, DiskSpaceReportRecord y)
            {
                if (x == null && y == null) return 0;
                else if (x == null) return -1;
                else if (y == null) return 1;
                if (x == y) return 0;

                return x.Size_10_0gb.CompareTo(y.Size_10_0gb);
            }
        }
        #endregion

        #region internal variables

        private int _Num_accounts;
        private int _Usage_in_bytes;
        private int _Avg_usage_in_mb;
        private int _Quota_in_mb;
        private int _Avg_quota_in_mb;
        private int _Size_0_1gb;
        private int _Size_0_2gb;
        private int _Size_0_3gb;
        private int _Size_0_4gb;
        private int _Size_0_5gb;
        private int _Size_0_6gb;
        private int _Size_0_7gb;
        private int _Size_0_8gb;
        private int _Size_0_9gb;
        private int _Size_1_0gb;
        private int _Size_1_5gb;
        private int _Size_2_0gb;
        private int _Size_2_5gb;
        private int _Size_3_0gb;
        private int _Size_3_5gb;
        private int _Size_4_0gb;
        private int _Size_4_5gb;
        private int _Size_5_0gb;
        private int _Size_5_5gb;
        private int _Size_6_0gb;
        private int _Size_6_5gb;
        private int _Size_7_0gb;
        private int _Size_7_5gb;
        private int _Size_8_0gb;
        private int _Size_8_5gb;
        private int _Size_9_0gb;
        private int _Size_9_5gb;
        private int _Size_10_0gb;

        #endregion

        #region properties

        /// <summary>
        /// The num_accounts field specifies the total number of user-accessible accounts in your domain. An account is considered user-accessible unless 
        /// you have suspended access to the account or account access has been suspended due to abuse or complaints.
        /// </summary>
        public int Num_accounts { get { return _Num_accounts; } set { _Num_accounts = value; } }

        /// <summary>
        /// The usage_in_bytes field identifies the total amount of disk space, in bytes, used by all active accounts in your domain.
        /// </summary>
        public int Usage_in_bytes { get { return _Usage_in_bytes; } set { _Usage_in_bytes = value; } }

        /// <summary>
        /// The avg_usage_in_mb field contains the average amount of disk space, in megabytes, used by each of your hosted accounts.
        /// </summary>
        public int Avg_usage_in_mb { get { return _Avg_usage_in_mb; } set { _Avg_usage_in_mb = value; } }

        /// <summary>
        /// The quota_in_mb field indicates the total amount of disk space available for all of the hosted accounts in your domain.
        /// </summary>
        public int Quota_in_mb { get { return _Quota_in_mb; } set { _Quota_in_mb = value; } }

        /// <summary>
        /// The avg_quota_in_mb field contains the average amount of disk space, in megabytes, available for each of your hosted accounts.
        /// </summary>
        public int Avg_quota_in_mb { get { return _Avg_quota_in_mb; } set { _Avg_quota_in_mb = value; } }

        /// <summary>
        /// The size_0_1gb field specifies the number of mailboxes using between 0.0 GB and 0.1 GB of disk space.
        /// </summary>
        public int Size_0_1gb { get { return _Size_0_1gb; } set { _Size_0_1gb = value; } }

        /// <summary>
        /// The size_0_2gb field specifies the number of mailboxes using between 0.1 GB and 0.2 GB of disk space.
        /// </summary>
        public int Size_0_2gb { get { return _Size_0_2gb; } set { _Size_0_2gb = value; } }

        /// <summary>
        /// The size_0_3gb field specifies the number of mailboxes using between 0.2 GB and 0.3 GB of disk space.
        /// </summary>
        public int Size_0_3gb { get { return _Size_0_3gb; } set { _Size_0_3gb = value; } }

        /// <summary>
        /// The size_0_4gb field specifies the number of mailboxes using between 0.3 GB and 0.4 GB of disk space.
        /// </summary>
        public int Size_0_4gb { get { return _Size_0_4gb; } set { _Size_0_4gb = value; } }

        /// <summary>
        /// The size_0_5gb field specifies the number of mailboxes using between 0.4 GB and 0.5 GB of disk space.
        /// </summary>
        public int Size_0_5gb { get { return _Size_0_5gb; } set { _Size_0_5gb = value; } }

        /// <summary>
        /// The size_0_6gb field specifies the number of mailboxes using between 0.5 GB and 0.6 GB of disk space.
        /// </summary>
        public int Size_0_6gb { get { return _Size_0_6gb; } set { _Size_0_6gb = value; } }

        /// <summary>
        /// The size_0_7gb field specifies the number of mailboxes using between 0.6 GB and 0.7 GB of disk space.
        /// </summary>
        public int Size_0_7gb { get { return _Size_0_7gb; } set { _Size_0_7gb = value; } }

        /// <summary>
        /// The size_0_8gb field specifies the number of mailboxes using between 0.7 GB and 0.8 GB of disk space.
        /// </summary>
        public int Size_0_8gb { get { return _Size_0_8gb; } set { _Size_0_8gb = value; } }

        /// <summary>
        /// The size_0_9gb field specifies the number of mailboxes using between 0.8 GB and 0.9 GB of disk space.
        /// </summary>
        public int Size_0_9gb { get { return _Size_0_9gb; } set { _Size_0_9gb = value; } }

        /// <summary>
        /// The size_1_0gb field specifies the number of mailboxes using between 0.9 GB and 1.0 GB of disk space.
        /// </summary>
        public int Size_1_0gb { get { return _Size_1_0gb; } set { _Size_1_0gb = value; } }

        /// <summary>
        /// The size_1_5gb field specifies the number of mailboxes using between 1.0 GB and 1.5 GB of disk space.
        /// </summary>
        public int Size_1_5gb { get { return _Size_1_5gb; } set { _Size_1_5gb = value; } }

        /// <summary>
        /// The size_2_0gb field specifies the number of mailboxes using between 1.5 GB and 2.0 GB of disk space.
        /// </summary>
        public int Size_2_0gb { get { return _Size_2_0gb; } set { _Size_2_0gb = value; } }

        /// <summary>
        /// The size_2_5gb field specifies the number of mailboxes using between 2.0 GB and 2.5 GB of disk space.
        /// </summary>
        public int Size_2_5gb { get { return _Size_2_5gb; } set { _Size_2_5gb = value; } }

        /// <summary>
        /// The size_3_0gb field specifies the number of mailboxes using between 2.5 GB and 3.0 GB of disk space.
        /// </summary>
        public int Size_3_0gb { get { return _Size_3_0gb; } set { _Size_3_0gb = value; } }

        /// <summary>
        /// The size_3_5gb field specifies the number of mailboxes using between 3.0 GB and 3.5 GB of disk space.
        /// </summary>
        public int Size_3_5gb { get { return _Size_3_5gb; } set { _Size_3_5gb = value; } }

        /// <summary>
        /// The size_4_0gb field specifies the number of mailboxes using between 3.5 GB and 4.0 GB of disk space.
        /// </summary>
        public int Size_4_0gb { get { return _Size_4_0gb; } set { _Size_4_0gb = value; } }

        /// <summary>
        /// The size_4_5gb field specifies the number of mailboxes using between 4.0 GB and 4.5 GB of disk space.
        /// </summary>
        public int Size_4_5gb { get { return _Size_4_5gb; } set { _Size_4_5gb = value; } }

        /// <summary>
        /// The size_5_0gb field specifies the number of mailboxes using between 4.5 GB and 5.0 GB of disk space.
        /// </summary>
        public int Size_5_0gb { get { return _Size_5_0gb; } set { _Size_5_0gb = value; } }

        /// <summary>
        /// The size_5_5gb field specifies the number of mailboxes using between 1.5 GB and 2.0 GB of disk space.
        /// </summary>
        public int Size_5_5gb { get { return _Size_5_5gb; } set { _Size_5_5gb = value; } }

        /// <summary>
        /// The size_6_0gb field specifies the number of mailboxes using between 5.5 GB and 6.0 GB of disk space.
        /// </summary>
        public int Size_6_0gb { get { return _Size_6_0gb; } set { _Size_6_0gb = value; } }

        /// <summary>
        /// The size_6_5gb field specifies the number of mailboxes using between 6.0 GB and 6.5 GB of disk space.
        /// </summary>
        public int Size_6_5gb { get { return _Size_6_5gb; } set { _Size_6_5gb = value; } }

        /// <summary>
        /// The size_7_0gb field specifies the number of mailboxes using between 6.5 GB and 7.0 GB of disk space.
        /// </summary>
        public int Size_7_0gb { get { return _Size_7_0gb; } set { _Size_7_0gb = value; } }

        /// <summary>
        /// The size_7_5gb field specifies the number of mailboxes using between 7.0 GB and 7.5 GB of disk space.
        /// </summary>
        public int Size_7_5gb { get { return _Size_7_5gb; } set { _Size_7_5gb = value; } }

        /// <summary>
        /// The size_8_0gb field specifies the number of mailboxes using between 7.5 GB and 8.0 GB of disk space.
        /// </summary>
        public int Size_8_0gb { get { return _Size_8_0gb; } set { _Size_8_0gb = value; } }

        /// <summary>
        /// The size_8_5gb field specifies the number of mailboxes using between 8.0 GB and 8.5 GB of disk space.
        /// </summary>
        public int Size_8_5gb { get { return _Size_8_5gb; } set { _Size_8_5gb = value; } }

        /// <summary>
        /// The size_9_0gb field specifies the number of mailboxes using between 8.5 GB and 9.0 GB of disk space.
        /// </summary>
        public int Size_9_0gb { get { return _Size_9_0gb; } set { _Size_9_0gb = value; } }

        /// <summary>
        /// The size_9_5gb field specifies the number of mailboxes using between 9.0 GB and 9.5 GB of disk space.
        /// </summary>
        public int Size_9_5gb { get { return _Size_9_5gb; } set { _Size_9_5gb = value; } }

        /// <summary>
        /// The size_10_0gb field specifies the number of mailboxes using between 9.5 GB and 10.0 GB of disk space.
        /// </summary>
        public int Size_10_0gb { get { return _Size_10_0gb; } set { _Size_10_0gb = value; } }

        #endregion
    }

    /// <summary>
    /// The email_clients report explains how users in your domain access their hosted accounts on a day-by-day basis. For each day, 
    /// the report lists the total number of accounts in your domain as well as the number and percentage of users who accessed their 
    /// accounts using WebMail. This report does not include suspended accounts in the account total.
    /// </summary>
    public class EmailClientsReportRecord : Google.Apps.Reporting.ReportRecord
    {
        #region overrides

        /// <summary>
        /// returns string of report record in format that like that originally delivered in report query
        /// </summary>
        /// <returns>report record in format that like that originally delivered in report query</returns>
        public override string ToString()
        {
            //date,num_accounts,web_mail_count,num_accounts_accessed,pop_count
            return this.Date.ToString("yyyyMMdd") + "," + this.Num_accounts + "," + this.Web_mail_count + "," + this.Num_accounts_accessed + "," + this.Pop_count;
        }

        #endregion

        #region instantiation

        /// <summary>
        /// default instantiation
        /// </summary>
        public EmailClientsReportRecord() { }

        /// <summary>
        /// parses string from google report.  
        /// API v1.0.1 this will be a comma delimited string
        /// </summary>
        /// <param name="googleReturnedReportRecordString">date,num_accounts,web_mail_count,num_accounts_accessed,pop_count</param>
        public EmailClientsReportRecord(string googleReturnedReportRecordString)
        {
            int expectedSplitLength = 5; // API v1.0.1 email clients report record
            string[] split = null;
            int currentPos = 0;
            try
            {
                split = googleReturnedReportRecordString.Split(',');
            }
            catch (Exception)
            {
                throw new FormatException("cannot split passed string in report record instantiation from google reporting returned string");
            }

            if (split.Length != expectedSplitLength)
            {
                throw new FormatException("passed string split to array of non-expected size - seen: " + split.Length + " expected: " + expectedSplitLength);
            }


            try
            {
                this._Date = new DateTime(Convert.ToInt32(split[0].Substring(0, 4)), Convert.ToInt32(split[0].Substring(4, 2)), Convert.ToInt32(split[0].Substring(6, 2))); currentPos++;
                this._Num_accounts = Convert.ToInt32(split[1]); currentPos++;
                this._Web_mail_count = Convert.ToInt32(split[2]); currentPos++;
                this._Num_accounts_accessed = Convert.ToInt32(split[3]); currentPos++;
                this._Pop_count = Convert.ToInt32(split[4]);
            }
            catch (Exception) { throw new FormatException("could not parse from data: " + split[currentPos]); }
        }

        #endregion

        #region comparers

        public static IComparer<EmailClientsReportRecord> EmailClientsNumAccountsSorter { get { return new EmailClientsNumAccountsComparer(); } }
        public static IComparer<EmailClientsReportRecord> EmailClientsWebMailCountSorter { get { return new EmailClientsWebMailCountComparer(); } }
        public static IComparer<EmailClientsReportRecord> EmailClientsNumAccountsAccessedSorter { get { return new EmailClientsNumAccountsAccessedComparer(); } }
        public static IComparer<EmailClientsReportRecord> EmailClientsPopCountSorter { get { return new EmailClientsPopCountComparer(); } }

        /// <summary>
        /// compare records based on num_accounts
        /// is int compare on Num_accounts property of EmailClients report record
        /// </summary>
        private class EmailClientsNumAccountsComparer : IComparer<EmailClientsReportRecord>
        {
            int IComparer<EmailClientsReportRecord>.Compare(EmailClientsReportRecord x, EmailClientsReportRecord y)
            {
                if (x == null && y == null) return 0;
                else if (x == null) return -1;
                else if (y == null) return 1;
                if (x == y) return 0;

                return x.Num_accounts.CompareTo(y.Num_accounts);
            }
        }

        /// <summary>
        /// compare records based on web_mail_count
        /// is int compare on Web_mail_count property of EmailClients report record
        /// </summary>
        private class EmailClientsWebMailCountComparer : IComparer<EmailClientsReportRecord>
        {
            int IComparer<EmailClientsReportRecord>.Compare(EmailClientsReportRecord x, EmailClientsReportRecord y)
            {
                if (x == null && y == null) return 0;
                else if (x == null) return -1;
                else if (y == null) return 1;
                if (x == y) return 0;

                return x.Web_mail_count.CompareTo(y.Web_mail_count);
            }
        }

        /// <summary>
        /// compare records based on num_accounts_accessed
        /// is int compare on Num_accounts_accessed property of EmailClients report record
        /// </summary>
        private class EmailClientsNumAccountsAccessedComparer : IComparer<EmailClientsReportRecord>
        {
            int IComparer<EmailClientsReportRecord>.Compare(EmailClientsReportRecord x, EmailClientsReportRecord y)
            {
                if (x == null && y == null) return 0;
                else if (x == null) return -1;
                else if (y == null) return 1;
                if (x == y) return 0;

                return x.Num_accounts_accessed.CompareTo(y.Num_accounts_accessed);
            }
        }

        /// <summary>
        /// compare records based on pop_count
        /// is int compare on Pop_count property of EmailClients report record
        /// </summary>
        private class EmailClientsPopCountComparer : IComparer<EmailClientsReportRecord>
        {
            int IComparer<EmailClientsReportRecord>.Compare(EmailClientsReportRecord x, EmailClientsReportRecord y)
            {
                if (x == null && y == null) return 0;
                else if (x == null) return -1;
                else if (y == null) return 1;
                if (x == y) return 0;

                return x.Pop_count.CompareTo(y.Pop_count);
            }
        }

        #endregion

        #region internal variables

        private int _Num_accounts;
        private int _Web_mail_count;
        private int _Num_accounts_accessed;
        private int _Pop_count;

        #endregion

        #region properties

        /// <summary>
        /// The num_accounts field specifies the total number of user-accessible accounts in your domain. An account is considered user-accessible unless 
        /// you have suspended access to the account or account access has been suspended due to abuse or complaints.
        /// </summary>
        public int Num_accounts { get { return _Num_accounts; } set { _Num_accounts = value; } }

        /// <summary>
        /// The web_mail_count field indicates how many users in your domain used WebMail to access their email on a particular day.
        /// </summary>
        public int Web_mail_count { get { return _Web_mail_count; } set { _Web_mail_count = value; } }

        /// <summary>
        /// The num_accounts_accessed field indicates how many users accessed their accounts using Webmail or POP on a particular day. 
        /// An account accessed using both is counted only once.
        /// </summary>
        public int Num_accounts_accessed { get { return _Num_accounts_accessed; } set { _Num_accounts_accessed = value; } }

        /// <summary>
        /// The pop_count field indicates how many users in your domain used POP to access their email on a particular day.
        /// </summary>
        public int Pop_count { get { return _Pop_count; } set { _Pop_count = value; } }

        #endregion
    }

    /// <summary>
    /// ** DEPRECATED -
    /// The quota_limit_accounts report contains a list of the accounts that are approaching or have exceeded their disk space quota. 
    /// An account will be included in this report if it has less than 5 percent of its quota remaining. This report does not include suspended accounts.
    ///  - DEPRECATED **
    /// </summary>
    [Obsolete]
    public class QuotaLimitAccountsReportRecord : Google.Apps.Reporting.ReportRecord
    {
        #region overrides

        /// <summary>
        /// returns string of report record in format that like that originally delivered in report query
        /// </summary>
        /// <returns>report record in format that like that originally delivered in report query</returns>
        public override string ToString()
        {
            //date,account_id,account_name,status,disk_space_in_mb,quota_in_mb
            return this.Date.ToString("yyyyMMdd") + "," + this.Account_name + "," + this.Quota_status.ToString() + "," + this.Disk_space_in_mb + "," + this.Quota_in_mb;
        }

        #endregion

        #region instantiation

        /// <summary>
        /// default instantiation
        /// </summary>
        public QuotaLimitAccountsReportRecord() { }

        /// <summary>
        /// parses string from google report.  
        /// API v1.0.1 this will be a comma delimited string
        /// </summary>
        /// <param name="googleReturnedReportRecordString">date,account_id,account_name,status,disk_space_in_mb,quota_in_mb</param>
        public QuotaLimitAccountsReportRecord(string googleReturnedReportRecordString)
        {
            int expectedSplitLength = 6; // API v1.0.1 quota limit quota limit accounts report record
            string[] split = null;
            int currentPos = 0;

            try
            {
                split = googleReturnedReportRecordString.Split(',');
            }
            catch (Exception)
            {
                throw new FormatException("cannot split passed string in report record instantiation from google reporting returned string");
            }

            if (split.Length != expectedSplitLength)
            {
                throw new FormatException("passed string split to array of non-expected size - seen: " + split.Length + " expected: " + expectedSplitLength);
            }

            try { this._Date = new DateTime(Convert.ToInt32(split[0].Substring(0, 4)), Convert.ToInt32(split[0].Substring(4, 2)), Convert.ToInt32(split[0].Substring(6, 2))); }
            catch (Exception) { throw new FormatException("could not parse DateTime from data: " + split[0]); }

            this._Account_id = split[1];

            this._Account_name = split[2];

            if (split[3] == "QUOTA_APPROACHING") this._Quota_status = Status.QUOTA_APPROACHING;
            else if (split[3] == "QUOTA_EXCEEDED") this._Quota_status = Status.QUOTA_EXCEEDED;
            else throw new FormatException("could not parse quota limit accounts report record status to valid value from data: " + split[3]);

            currentPos = 4;
            try
            {
                this._Disk_space_in_mb = Convert.ToInt32(split[4]); currentPos++;
                this._Quota_in_mb = Convert.ToInt32(split[5]);
            }
            catch (Exception) { throw new FormatException("could not parse from data: " + split[currentPos]); }
        }

        #endregion

        #region enum

        /// <summary>
        /// enum of quota status - reporting API v1.0.1 currently has values for QUOTA_APPROACHING, QUOTA_EXCEEDED
        /// </summary>
        public enum Status { QUOTA_APPROACHING, QUOTA_EXCEEDED }

        #endregion

        #region comparers

        public static IComparer<QuotaLimitAccountsReportRecord> QuotaLimitAccountsIdSorter { get { return new QuotaLimitAccountsIdComparer(); } }
        public static IComparer<QuotaLimitAccountsReportRecord> QuotaLimitAccountsNameSorter { get { return new QuotaLimitAccountsNameComparer(); } }
        public static IComparer<QuotaLimitAccountsReportRecord> QuotaLimitAccountsStatusSorter { get { return new QuotaLimitAccountsStatusComparer(); } }
        public static IComparer<QuotaLimitAccountsReportRecord> QuotaLimitAccountsDiskSpaceInMBSorter { get { return new QuotaLimitAccountsDiskSpaceInMBComparer(); } }
        public static IComparer<QuotaLimitAccountsReportRecord> QuotaLimitAccountsQuotaInMBSorter { get { return new QuotaLimitAccountsQuotaInMBComparer(); } }

        /// <summary>
        /// compare records based on account_id
        /// is string compare on Account_id property of Quota Limit Accounts report record
        /// </summary>
        private class QuotaLimitAccountsIdComparer : IComparer<QuotaLimitAccountsReportRecord>
        {
            int IComparer<QuotaLimitAccountsReportRecord>.Compare(QuotaLimitAccountsReportRecord x, QuotaLimitAccountsReportRecord y)
            {
                if (x == null && y == null) return 0;
                else if (x == null) return -1;
                else if (y == null) return 1;
                if (x == y) return 0;

                if (x.Account_id == null && y.Account_id == null) return 0;
                else if (x.Account_id == null) return -1;
                else if (y.Account_id == null) return 1;
                if (x.Account_id == y.Account_id) return 0;

                return x.Account_id.CompareTo(y.Account_id);
            }
        }

        /// <summary>
        /// compare records based on account_name
        /// is string compare on Account_name property of Quota Limit Accounts report record
        /// </summary>
        private class QuotaLimitAccountsNameComparer : IComparer<QuotaLimitAccountsReportRecord>
        {
            int IComparer<QuotaLimitAccountsReportRecord>.Compare(QuotaLimitAccountsReportRecord x, QuotaLimitAccountsReportRecord y)
            {
                if (x == null && y == null) return 0;
                else if (x == null) return -1;
                else if (y == null) return 1;
                if (x == y) return 0;

                if (x.Account_name == null && y.Account_name == null) return 0;
                else if (x.Account_name == null) return -1;
                else if (y.Account_name == null) return 1;
                if (x.Account_name == y.Account_name) return 0;

                return x.Account_name.CompareTo(y.Account_name);
            }
        }

        /// <summary>
        /// compare records based on status
        /// is enum compare on Quota_status property of Quota Limit Accounts report record
        /// </summary>
        private class QuotaLimitAccountsStatusComparer : IComparer<QuotaLimitAccountsReportRecord>
        {
            int IComparer<QuotaLimitAccountsReportRecord>.Compare(QuotaLimitAccountsReportRecord x, QuotaLimitAccountsReportRecord y)
            {
                if (x == null && y == null) return 0;
                else if (x == null) return -1;
                else if (y == null) return 1;
                if (x == y) return 0;

                return x.Quota_status.CompareTo(y.Quota_status);
            }
        }

        /// <summary>
        /// compare records based on disk_space_in_mb
        /// is int compare on Disk_space_in_mb property of Quota Limit Accounts report record
        /// </summary>
        private class QuotaLimitAccountsDiskSpaceInMBComparer : IComparer<QuotaLimitAccountsReportRecord>
        {
            int IComparer<QuotaLimitAccountsReportRecord>.Compare(QuotaLimitAccountsReportRecord x, QuotaLimitAccountsReportRecord y)
            {
                if (x == null && y == null) return 0;
                else if (x == null) return -1;
                else if (y == null) return 1;
                if (x == y) return 0;

                return x.Disk_space_in_mb.CompareTo(y.Disk_space_in_mb);
            }
        }

        /// <summary>
        /// compare records based on quota_in_mb
        /// is int compare on Quota_in_mb property of Quota Limit Accounts report record
        /// </summary>
        private class QuotaLimitAccountsQuotaInMBComparer : IComparer<QuotaLimitAccountsReportRecord>
        {
            int IComparer<QuotaLimitAccountsReportRecord>.Compare(QuotaLimitAccountsReportRecord x, QuotaLimitAccountsReportRecord y)
            {
                if (x == null && y == null) return 0;
                else if (x == null) return -1;
                else if (y == null) return 1;
                if (x == y) return 0;

                return x.Quota_in_mb.CompareTo(y.Quota_in_mb);
            }
        }
        #endregion

        #region internal variables

        private string _Account_id;
        private string _Account_name;
        private Status _Quota_status;
        private int _Disk_space_in_mb;
        private int _Quota_in_mb;

        #endregion

        #region properties

        /// <summary>
        /// The account_id field contains an ID that uniquely identifies a hosted account. Google will assign an account ID to each hosted account 
        /// that you create, and this ID will not change for the life of the account.
        /// </summary>
        public string Account_id { get { return _Account_id; } set { _Account_id = value; } }

        /// <summary>
        /// The account_name field contains the user's email address, including a username and your domain name – e.g. admin@example.com.
        /// </summary>
        public string Account_name { get { return _Account_name; } set { _Account_name = value; } }

        /// <summary>
        /// The status field indicates that an account has almost reached or has exceeded its disk space quota. Valid values for this field 
        /// are QUOTA_APPROACHING and QUOTA_EXCEEDED.
        /// </summary>
        public Status Quota_status { get { return _Quota_status; } set { _Quota_status = value; } }

        /// <summary>
        /// The disk_space_in_mb field indicates the amount of disk space, in megabytes, that is being used by a particular account.
        /// </summary>
        public int Disk_space_in_mb { get { return _Disk_space_in_mb; } set { _Disk_space_in_mb = value; } }

        /// <summary>
        /// The quota_in_mb field indicates the total amount of disk space available for all of the hosted accounts in your domain.
        /// </summary>
        public int Quota_in_mb { get { return _Quota_in_mb; } set { _Quota_in_mb = value; } }

        #endregion
    }

    /// <summary>
    /// The summary report contains the total number of accounts, total mailbox usage in bytes and total mailbox quota in megabytes for your domain. 
    /// Each row in the report contains data for one day. This report does not include information for suspended accounts.
    /// </summary>
    public class SummaryReportRecord : Google.Apps.Reporting.ReportRecord
    {
        /// <summary>
        /// returns string of report record in format that like that originally delivered in report query
        /// </summary>
        /// <returns>report record in format that like that originally delivered in report query</returns>
        public override string ToString()
        {
            //date,num_accounts,usage_in_bytes,quota_in_mb
            return this.Date.ToString("yyyyMMdd") + "," + this.Num_accounts + "," + this.Usage_in_bytes + "," + this.Quota_in_mb;
        }

        #region instantiation

        /// <summary>
        /// default instantiation
        /// </summary>
        public SummaryReportRecord() { }

        /// <summary>
        /// parses string from google report.  
        /// API v1.0.1 this will be a comma delimited string
        /// </summary>
        /// <param name="googleReturnedReportRecordString">date,num_accounts,usage_in_bytes,quota_in_mb</param>
        public SummaryReportRecord(string googleReturnedReportRecordString)
        {
            int expectedSplitLength = 4; // API v1.0.1 summary summary report record
            string[] split = null;
            int currentPos = 0;

            try
            {
                split = googleReturnedReportRecordString.Split(',');
            }
            catch (Exception)
            {
                throw new FormatException("cannot split passed string in report record instantiation from google reporting returned string");
            }

            if (split.Length != expectedSplitLength)
            {
                throw new FormatException("passed string split to array of non-expected size - seen: " + split.Length + " expected: " + expectedSplitLength);
            }

            try
            {
                this._Date = new DateTime(Convert.ToInt32(split[0].Substring(0, 4)), Convert.ToInt32(split[0].Substring(4, 2)), Convert.ToInt32(split[0].Substring(6, 2))); currentPos++;
                this._Num_accounts = Convert.ToInt32(split[1]); currentPos++;
                this.Usage_in_bytes = Convert.ToInt32(split[2]); currentPos++;
                this._Quota_in_mb = Convert.ToInt32(split[3]);
            }
            catch (Exception) { throw new FormatException("could not parse from data: " + split[currentPos]); }
        }

        #endregion

        #region comparers

        public static IComparer<SummaryReportRecord> SummaryNumAccountsSorter { get { return new SummaryNumAccountsComparer(); } }
        public static IComparer<SummaryReportRecord> SummaryUsageInBytesSorter { get { return new SummaryUsageInBytesComparer(); } }
        public static IComparer<SummaryReportRecord> SummaryQuotaInMbSorter { get { return new SummaryQuotaInMbComparer(); } }

        /// <summary>
        /// compare records based on num_accounts
        /// is string compare on Num_accounts property of Summary report record
        /// </summary>
        private class SummaryNumAccountsComparer : IComparer<SummaryReportRecord>
        {
            int IComparer<SummaryReportRecord>.Compare(SummaryReportRecord x, SummaryReportRecord y)
            {
                if (x == null && y == null) return 0;
                else if (x == null) return -1;
                else if (y == null) return 1;
                if (x == y) return 0;

                return x.Num_accounts.CompareTo(y.Num_accounts);
            }
        }

        /// <summary>
        /// compare records based on usage_in_bytes
        /// is string compare on Usage_in_bytes property of Summary report record
        /// </summary>
        private class SummaryUsageInBytesComparer : IComparer<SummaryReportRecord>
        {
            int IComparer<SummaryReportRecord>.Compare(SummaryReportRecord x, SummaryReportRecord y)
            {
                if (x == null && y == null) return 0;
                else if (x == null) return -1;
                else if (y == null) return 1;
                if (x == y) return 0;

                return x.Usage_in_bytes.CompareTo(y.Usage_in_bytes);
            }
        }

        /// <summary>
        /// compare records based on quota_in_mb
        /// is string compare on Quota_in_mb property of Summary report record
        /// </summary>
        private class SummaryQuotaInMbComparer : IComparer<SummaryReportRecord>
        {
            int IComparer<SummaryReportRecord>.Compare(SummaryReportRecord x, SummaryReportRecord y)
            {
                if (x == null && y == null) return 0;
                else if (x == null) return -1;
                else if (y == null) return 1;
                if (x == y) return 0;

                return x.Quota_in_mb.CompareTo(y.Quota_in_mb);
            }
        }
        #endregion

        #region internal variables

        private int _Num_accounts;
        private int _Usage_in_bytes;
        private int _Quota_in_mb;

        #endregion

        #region properties

        /// <summary>
        /// The num_accounts field specifies the total number of user-accessible accounts in your domain. An account is considered user-accessible unless 
        /// you have suspended access to the account or account access has been suspended due to abuse or complaints.
        /// </summary>
        public int Num_accounts { get { return _Num_accounts; } set { _Num_accounts = value; } }

        /// <summary>
        /// The usage_in_bytes field specifies the total amount of disk space, in bytes, used by all in your domain.
        /// </summary>
        public int Usage_in_bytes { get { return _Usage_in_bytes; } set { _Usage_in_bytes = value; } }

        /// <summary>
        /// The quota_in_mb field indicates the total amount of disk space available for all of the hosted accounts in your domain.
        /// </summary>
        public int Quota_in_mb { get { return _Quota_in_mb; } set { _Quota_in_mb = value; } }

        #endregion
    }

    /// <summary>
    /// The suspended_accounts report lists all of the suspended accounts in your domain on a particular day.
    /// </summary>
    [Obsolete]
    public class SuspendedAccountsReportRecord : Google.Apps.Reporting.ReportRecord
    {
        /// <summary>
        /// returns string of report record in format that like that originally delivered in report query
        /// </summary>
        /// <returns>report record in format that like that originally delivered in report query</returns>
        public override string ToString()
        {
            //date,account_id,account_name,status,reason
            return this.Date.ToString("yyyyMMdd") + "," + this.Account_id + "," + this.Account_name + "," + this.Suspension_status.ToString() + "," + this.Suspension_reason;
        }

        /// <summary>
        /// enum of suspension status - reporting API v1.0.1 currently has values for SUSPENDED_FOR_ABUSE, SUSPENDED_BY_ADMIN, OTHER
        /// </summary>
        public enum Status { SUSPENDED_FOR_ABUSE, SUSPENDED_BY_ADMIN, OTHER }

        #region instantiation

        /// <summary>
        /// default instantiation
        /// </summary>
        public SuspendedAccountsReportRecord() { }

        /// <summary>
        /// parses string from google report.  
        /// API v1.0.1 this will be a comma delimited string
        /// </summary>
        /// <param name="googleReturnedReportRecordString">date,account_id,account_name,status,reason</param>
        public SuspendedAccountsReportRecord(string googleReturnedReportRecordString)
        {
            int expectedSplitLength = 5; // API v1.0.1 suspended accounts summary report record

            string[] split = null;

            try
            {
                split = googleReturnedReportRecordString.Split(',');
            }
            catch (Exception)
            {
                throw new FormatException("cannot split passed string in report record instantiation from google reporting returned string");
            }

            if (split.Length != expectedSplitLength)
            {
                throw new FormatException("passed string split to array of non-expected size - seen: " + split.Length + " expected: " + expectedSplitLength);
            }

            try { this._Date = new DateTime(Convert.ToInt32(split[0].Substring(0, 4)), Convert.ToInt32(split[0].Substring(4, 2)), Convert.ToInt32(split[0].Substring(6, 2))); }
            catch (Exception) { throw new FormatException("could not parse DateTime from data: " + split[0]); }

            this._Account_id = split[1];
            this._Account_name = split[2];

            if (split[3] == "SUSPENDED_BY_ADMIN") this._Suspension_status = Status.SUSPENDED_BY_ADMIN;
            else if (split[3] == "SUSPENDED_FOR_ABUSE") this._Suspension_status = Status.SUSPENDED_FOR_ABUSE;
            else if (split[3] == "OTHER") this._Suspension_status = Status.OTHER;
            else throw new FormatException("could not parse Suspended accounts report record status to valid value from data: " + split[3]);

            this._Suspension_reason = split[4];
        }

        #endregion


        #region comparers

        public static IComparer<SuspendedAccountsReportRecord> SuspendedAccountsAccountIdSorter { get { return new SuspendedAccountsAccountIdComparer(); } }
        public static IComparer<SuspendedAccountsReportRecord> SuspendedAccountsAccountNameSorter { get { return new SuspendedAccountsAccountNameComparer(); } }
        public static IComparer<SuspendedAccountsReportRecord> SuspendedAccountsAccountStatusSorter { get { return new SuspendedAccountsAccountStatusComparer(); } }
        public static IComparer<SuspendedAccountsReportRecord> SuspendedAccountsAccountSuspensionReasonSorter { get { return new SuspendedAccountsAccountSuspensionReasonComparer(); } }
        /// <summary>
        /// compare records based on account_id
        /// is string compare on Account_id property of Suspended Accounts report record
        /// </summary>
        private class SuspendedAccountsAccountIdComparer : IComparer<SuspendedAccountsReportRecord>
        {
            int IComparer<SuspendedAccountsReportRecord>.Compare(SuspendedAccountsReportRecord x, SuspendedAccountsReportRecord y)
            {
                if (x == null && y == null) return 0;
                else if (x == null) return -1;
                else if (y == null) return 1;
                if (x == y) return 0;


                if (x.Account_id == null && y.Account_id == null) return 0;
                else if (x.Account_id == null) return -1;
                else if (y.Account_id == null) return 1;
                if (x.Account_id == y.Account_id) return 0;

                return x.Account_id.CompareTo(y.Account_id);
            }
        }

        /// <summary>
        /// compare records based on account_name
        /// is string compare on Account_name property of Suspended Accounts report record
        /// </summary>
        private class SuspendedAccountsAccountNameComparer : IComparer<SuspendedAccountsReportRecord>
        {
            int IComparer<SuspendedAccountsReportRecord>.Compare(SuspendedAccountsReportRecord x, SuspendedAccountsReportRecord y)
            {
                if (x == null && y == null) return 0;
                else if (x == null) return -1;
                else if (y == null) return 1;
                if (x == y) return 0;


                if (x.Account_name == null && y.Account_name == null) return 0;
                else if (x.Account_name == null) return -1;
                else if (y.Account_name == null) return 1;
                if (x.Account_name == y.Account_name) return 0;

                return x.Account_name.CompareTo(y.Account_name);
            }
        }

        /// <summary>
        /// compare records based on status
        /// is string compare on Suspension_status property of Suspended Accounts report record
        /// </summary>
        private class SuspendedAccountsAccountStatusComparer : IComparer<SuspendedAccountsReportRecord>
        {
            int IComparer<SuspendedAccountsReportRecord>.Compare(SuspendedAccountsReportRecord x, SuspendedAccountsReportRecord y)
            {
                if (x == null && y == null) return 0;
                else if (x == null) return -1;
                else if (y == null) return 1;
                if (x == y) return 0;

                return x.Suspension_status.CompareTo(y.Suspension_status);
            }
        }

        /// <summary>
        /// compare records based on reason
        /// is string compare on Suspension_reason property of Suspended Accounts report record
        /// </summary>
        private class SuspendedAccountsAccountSuspensionReasonComparer : IComparer<SuspendedAccountsReportRecord>
        {
            int IComparer<SuspendedAccountsReportRecord>.Compare(SuspendedAccountsReportRecord x, SuspendedAccountsReportRecord y)
            {
                if (x == null && y == null) return 0;
                else if (x == null) return -1;
                else if (y == null) return 1;
                if (x == y) return 0;


                if (x.Suspension_reason == null && y.Suspension_reason == null) return 0;
                else if (x.Suspension_reason == null) return -1;
                else if (y.Suspension_reason == null) return 1;
                if (x.Suspension_reason == y.Suspension_reason) return 0;

                return x.Suspension_reason.CompareTo(y.Suspension_reason);
            }
        }

        #endregion

        #region internal variables

        private string _Account_id;
        private string _Account_name;
        private Status _Suspension_status;
        private string _Suspension_reason;
        //moo
        #endregion

        #region properties

        /// <summary>
        /// The account_id field contains an ID that uniquely identifies a hosted account. Google will assign an account ID to each hosted account 
        /// that you create, and this ID will not change for the life of the account.
        /// </summary>
        public string Account_id { get { return _Account_id; } set { _Account_id = value; } }

        /// <summary>
        /// The account_name field contains the user's email address, including a username and your domain name – e.g. admin@example.com.
        /// </summary>
        public string Account_name { get { return _Account_name; } set { _Account_name = value; } }

        /// <summary>
        /// The status field provides some information as to why an account has been suspended. The suspension_reason field may contain 
        /// additional information explaining why an account was suspended.
        /// Valid values for this field are SUSPENDED_FOR_ABUSE, SUSPENDED_BY_ADMIN and OTHER.
        /// </summary>
        public Status Suspension_status { get { return _Suspension_status; } set { _Suspension_status = value; } }

        /// <summary>
        /// The suspension_reason field identifies the reason that an account was suspended.
        /// </summary>
        public string Suspension_reason { get { return _Suspension_reason; } set { _Suspension_reason = value; } }

        #endregion
    }

}
